Yii views are pretty powerful and have many features. One of them is that you can use controller context in a view. So, let's try it.
class WebsiteController extends CController { function actionIndex() { $this->pageTitle = 'Controller context test'; $this->render('index'), } function hello() { if(!empty($_GET['name'])) echo 'Hello, '.$_GET['name'].'!'; } }
<h1><?php echo $this->pageTitle?></h1> <p>Hello call. <?php $this->hello()?></p> <?php $this->widget('zii.widgets.CMenu',array( 'items'=>array( array('label'=>'Home', 'url'=>array('index')), array('label'=>'Yiiframework home', 'url'=>'http://yiiframework.ru/'), ), ))?>
/index.php?r=website/index
.We are using $this
in a view to refer to a currently running controller. When doing it, we can call a controller method and access its properties. The most useful property is pageTitle
, which refers to the current page title. There are many built-in methods that are extremely useful in views such as renderPartials
and widget
.
The following URL contains API documentation for CController
where you can get a good list of methods you can use in your view:
3.129.249.105