开发者

Yii MVC + Web Service = Not MVC?

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 Cer开发者_开发技巧ealStuff 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!


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜