YII MVC Viewの$this
1107 ワード
WebsiteController
view
viewの中の$thisはそのcontrollerの中の属性と方法を呼び出すことができて、例えば
$this->getLayoutFile $this->renderPartial
$this->widget
同じwidgetのviewでもwidgetのプロパティとメソッドを呼び出すことができます
<?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のプロパティとメソッドを呼び出すことができます