2. Yii Application Architecture (MVC)
As mentioned, Yii is an MVC framework for PHP. MVC framework refers to the Model View Controller development paradigm and is an excellent framework for providing structure to a project.
The primary concept of MVC is the separation of function from presentation.
2.1 Model
The model is an object representing the data that drives a web application and the manipulation of such data. Generally, the model is the interface to the back end database.
2.1.1 CRUD
The model is tasked with managing what is referred to as CRUD operations. The acronym stands for Create, Read, Update and Delete.
Thus, it is through the model that database queries are executed to retrieve data records [R], to create new records [C], to update existing records [U] and to delete database records [D].
2.2 View
The view is the presentation layer. This is where the actual HTML code will be placed to render the queried data to the user. Templates are generally used to provide the structure.
YII separates the page layout from the content. The same layout template can be used for all pages presented, or the pages can be assigned to multiple layouts.
The concept of Themes is also supported in YII 2.0.
2.3 Controller
The controller is the glue that connects the data provided by the model to the presentation structure provided by the view.
A good metaphor is to compare the controller to a traffic cop. When a page is requested by a user's browser, the request goes to the controller, which in turn calls the appropriate model to pull the data and routes it to the appropriate view to present that data.
If any work is to be done, it is generally done in the controller.