In the MVC architecture, the Controller reacts to a user request. In doing so, the Controller often loads an instance of a particular Model and then renders a specific View. “Rendering” just means compiling all the pieces together, including static text (HTML and such) and the output from executed PHP code. For example, when a user goes to a page for updating a record, the Controller loads the associated record, and then renders the “update” View, which will display the pre-populated form:
\[php\]
public function actionUpdate($id) {
$data=$this->loadModel($id);
\[/php\]
Note: That method would also have code in it for handling the submission of the update form, but I’m trying not to complicate the discussion.
As you can see in that code, the render() method, defined in the CController class, is how a View file is chosen for rendering. The first argument to the method is the View file to be rendered, without its .php extension. The render() method will render the View file within the appropriate layout file. In other words, the View file will be rendered with its context. The above code renders update.php, for the associated Controller, wrapped within the views/layouts/main.php layout file (the default).
…