您的位置:首页 > Web前端

Difference between Controller and Model in MVC

2015-01-08 18:14 501 查看
http://stackoverflow.com/questions/6423418/difference-between-controller-and-model-in-mvc

Generally speaking - a model should know stuff about it's own data. So anything related purely to a model's own data - should go in the model.

Eg the hash_password and email-validation methods - a model should know how to validate or update it's own data-fields, so those should go in the model.

However a controller should know about how to direct user actions appropriately and to load the correct models for views etc.

EG the session-related method should go in the controller, because the session is used for storing the user's state (based on past actions).

The "generate random string" method is very vague and may be used everywhere. I'd put that in a separate library possibly included in the model/controller as appropriate.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: