What is model,view,controller?

Answer

Models represent the underlying data structure of a Web application. Models are often shared among different sub-applications of a Web application. For example, a LoginForm model may be used by both the front end and the back end of an application; a News model may be used by the console commands, Web APIs, and the front/back end of an application. Therefore, models

·         should contain properties to represent specific data;
·         should contain business logic (e.g. validation rules) to ensure the represented data fulfills the design requirement;
·         may contain code for manipulating data. For example, a SearchForm model, besides representing the search input data, may contain a search method to implement the actual search.
=> Views are responsible for presenting models in the format that end users desire. In general, views
·         should mainly contain presentational code, such as HTML, and simple PHP code to traverse, format and render data;
·         should avoid containing code that performs explicit DB queries. Such code is better placed in models.
·         should avoid direct access to $_GET$_POST, or other similar variables that represent the end user request. This is the controller's job. The view should be focused on the display and layout of the data provided to it by the controller and/or model, but not attempting to access request variables or the database directly.
·         may access properties and methods of controllers and models directly. However, this should be done only for the purpose of presentation.
=>Controllers are the glue that binds models, views and other components together into a runnable application. Controllers are responsible for dealing directly with end user requests. Therefore, controllers
·         may access $_GET$_POST and other PHP variables that represent user requests;
·         may create model instances and manage their life cycles. For example, in a typical model update action, the controller may first create the model instance; then populate the model with the user input from$_POST; after saving the model successfully, the controller may redirect the user browser to the model detail page. Note that the actual implementation of saving a model should be located in the model instead of the controller.
·         should avoid containing embedded SQL statements, which are better kept in models.
·         should avoid containing any HTML or any other presentational markup. This is better kept in views.
 

All yii Questions

Ask your interview questions on yii

Write Your comment or Questions if you want the answers on yii from yii Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---