0

I am embarking on creating a Yii project that basically has a shared data model (let's say CerealStuff) with a front-end web site (call it site), admin site admin, and web service ws. I am new to the whole MVC thing and I wanted to know how I should design this project to stay consistent with Yii/MVC best practices. So far I have identified two basic options:

  1. Create models CerealStuff at root, create three modules site, admin, and ws each with their own controllers;
  2. Create models CerealStuff at root, create two modules admin and public with public containing controllers that handle Site and have @soap declarations to handle ws stuff.

I know that option 2 reduces the total amount of reproduced coding but it does not feel as clean quite honestly. Also I feel like maybe a modern web app should be such that even the "site" (view) uses the web service to access the database.

Tell me what to think!

2 Answers 2

0

I'm exposing a simple web service in my app, and I went with a separate (soap) controller.

If you follow the fat model / skinny controller paradigm, it's pretty simple to tack on a web service front end to your models.

Edit: better example of fat models: http://www.therailsway.com/2007/6/1/railsconf-recap-skinny-controllers

Sign up to request clarification or add additional context in comments.

2 Comments

So the downside to this is that you end up making changes in two places to shared functions in both front-end and web service controllers? Say you have a controller that does some complicated output formatting.
Not really. See the link about the skinny controller -- your logic is going in the model. Your controller shouldn't be doing complicated output formatting, that's what your view is for.
0

Read this article to see an example of MVC structured Yii project with two entrance points for front-end and back-end. Once learned this you can add another entrance point easily for ws.

As you can see all models are shared between modules. Controllers, config files and views are separate. Views can be configured as shared as well. I used this type of structure in many projects and never had any issues with extending or scaling.

2 Comments

No it doesn't mean it should have different entry point. Yii allows you create almost any type of configuration. There are many ways to organize your file structure.
There are times when due to workflow or other issues it's nice to have separate protected directories for front and back (using the example in that article) and I've simply soft-linked the models directory, which basically accomplishes the same thing while allowing for separation of the rest of the code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.