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.
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.
相关文章推荐
- Model View Controller (MVC) Using C#, Delegates and Events in .NET
- HTML5, jQuery Mobile and ASP.NET MVC 4 – Using the ViewModel between the model and controller
- Find the difference between two days in days, months and years
- The difference between an Isolated host and an In-Process host...
- Difference between event.target and event.currentTarget properties in an event object.
- Difference between release and dealloc in objective-c
- [Qt] difference between QItemSelectionModel::selectedIndexes () and QItemSelectionModel::selectedRows ( int column = 0 )
- Difference between STA and MTA in thread
- difference between Interface and abstract class in Java
- What is difference between And and Andalso in VB.net ?
- Difference between release and dealloc in objective-c
- difference between visibility and display in css
- Understand the difference between IN and EXISTS in subqueries
- Difference between pointer variable and reference variable in C++
- The flow of MVC in Spring -- Part I -- Dispatcher and Controller
- The difference between iostream and stdio in MPI
- Differences between Name and x:Name in XAML
- [WPF]The differences between Text Box and Text Block in Blend
- Difference between href and reload for refreshing in javascript
- Difference between Externalizable and Serializable in Java