Using the controller context in a view
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.
Getting ready
Set up a new application using yiic webapp.
How to do it...
Create a controller as follows:
class WebsiteController extends CController { function actionIndex() { $this->pageTitle = 'Controller context test'; $this->render('index'); } function hello() { if(!empty($_GET['name'])) echo 'Hello, '.$_GET['name'].'!'; } }Now, we will create a view showing what we can do:
<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/'), ), ))?>In order to test it you can follow
/index.php...