首页 > 活着 > YII MVC View中的$this

YII MVC View中的$this

WebsiteController

Java代码
1. 2.class WebsiteController extends CController
3.{
4. function actionIndex()
5. {
6. $this->pageTitle = ‘Controller context test';
7. $this->render(‘index’);
8. }
9. function hello()
10. {
11. if(!empty($_GET[‘name’]))
12. echo ‘Hello, ‘.$_GET[‘name’].’!';
13. }
14.}
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

Java代码
1.

pageTitle?>

2.

Hello call. hello()?>

3.widget(‘zii.widgets.CMenu’,array(
4.’items’=>array(
5.array(‘label’=>’Home’, ‘url’=>array(‘index’)),
6.array(‘label’=>’Yiiframework home’,
7.’url’=>’http://yiiframework.ru/’,
8.),
9.))?>

pageTitle?>

Hello call. hello()?>

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

WebsiteController Java代码 1. 2. Hello call. 3.

  1. 还没有评论
评论提交中, 请稍候...

留言

(Spamcheck Enabled)

Trackbacks & Pingbacks ( 0 )
  1. 还没有 trackbacks