protected/widgets/default 的目录下新建 ceshi.php
ceshi.php
class ceshi extends CWidget { //一定要继承CWidget
public $id='1';
public $name= 'zhangsan';/
public function run() {
$this->render('ceshi');
}
}
?>
//protected/widgets/default/views的目录下新建ceshi.php
ceshi.php
<div>my ID is <?php echo $this->id;?> </div>
<div>my ID is <?php echo $this->name;?> </div>
调用的方式 (任意地方都可以调用)
<?php $this->widget('application.widgets.default.ceshi', array('id' => '1','name'=>'lisi'));?>