1、在控制器类里定义一个公共成员属性
<?php
class SiteController extends CController{
public $variable = null;
}
?>2、在action操作方法里赋值给$variable变量
<?php
public function actionIndex() {
$this->variable = '123456';
}
?>3、在layouts模板里就可以这样调用$variable变量了:
<?php echo $this->variable; ?>
另外还可以通过控制器中的自带的params参数来传值,原理和上面的一样,只是不需要我们自己定义变量了