`
hudeyong926
  • 浏览: 2018590 次
  • 来自: 武汉
社区版块
存档分类
最新评论

YII MVC View中的$this

 
阅读更多

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的属性和方法

 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics