clistView 中使用 所在controller里的参数(某一个类的实例)

在某一action种,声明了某class的实例 A, 在clistView 中调用该A,可以通过

$this->render('index',array(
            'A' => $A,
            'dataProvider'=>$dataProvider,

    ));
   

然后在views里面,这里以index.php 这个view 为例子:

$this->widget('zii.widgets.CListView', array(
    'dataProvider'=>$dataProvider,
    'itemView'=>'_view',
   
    'viewData'=>array('A'=>$A),


这样就可以在_view.php里调用 $A 了。


参考:

Yii::ClistView中可以使用的变量


  • $this: refers to the owner of this list view widget. For example, if the widget is in the view of a controller, then $this refers to the controller.
  • $data: refers to the data item currently being rendered.
  • $index: refers to the zero-based index of the data item currently being rendered.
  • $widget: refers to this list view widget instance.

另外,还可以通过以下方式来直接向CListView传递变量

//生成view
$this->widget('zii.widgets.CListView', array(
	'dataProvider'=>$dataProvider,
	'itemView'=>'_view',
	'viewData'=>array('userList'=>'hi'),
));


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值