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

来源:互联网 发布:怎么联系淘宝云客服 编辑:程序博客网 时间:2024/05/16 09:45

在某一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'),));