WebsiteController
- <?php
- class WebsiteController extends CController
- {
- function actionIndex()
- {
- $this->pageTitle = 'Controller context test';
- $this->render('index');
- }
- function hello()
- {
- if(!empty($_GET['name']))
- echo 'Hello, '.$_GET['name'].'!';
- }
- }
view
- <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/',
- ),
- ))?>
在view里的$this可以调用它的controller里面的属性和方法,如
$this->getLayoutFile
$this->renderPartial
$this->widget
同理widget中的view也可以调用widget的属性和方法