Views

Chapters

A view is a PHP script consisting mainly of user interface elements.

It can contain PHP statements, but it is recommended that these statements should not alter data models and should remain relatively simple.

In the spirit of separating of logic and presentation, large chunks of logic should be placed in controllers or models rather than in views.

A view has a name which is used to identify the view script file when rendering.

The name of a view is the same as the name of its view script.

For example, the view name edit refers to a view script named edit.php. To render a view, call CController::render or CWidget::render with the name of the view. The method will look for the corresponding view file under the directory protected/views/ControllerID.

Inside the view script, we can access the controller instance using $this. We can thus pull in any property of the controller by evaluating $this→propertyName in the view.

We can also use the following push approach to pass data to the view:


$this->render('edit', array(
    'var1'=>$value1,
    'var2'=>$value2,
));

In the above, the render() method will extract the second array parameter into variables. As a result, in the view script we can access the local variables $var1 and $var2.

More about views you can find here