2

我想要传递给gridview的第一个和最后一个记录id表单$dataprovider,我需要传递给这个链接。

array(
         'name' => 'msg',
         'value' => 'CHtml::link(substr(strip_tags($data->msg),0,30)." .....",Yii::app()->createUrl("Mail/view",array("id"=>$data->primaryKey,"flag"=>"inbox","tab"=>'.$tab.',"category"=>'.$category.')))',
         'type' => 'raw',
         'header' => 'Message',
     ), 
4

1 回答 1

0
  1. 在控制器中声明两个属性。
public $first=null;
public $last=null;
  1. 在控制器中定义一个函数来呈现您的链接
public function renderMailViewLink($data,$row){
               // you can return anything you want here. whether a link or whatever
               // access $this->first->id , $this->last->id

   return CHtml::link($data->anyAttribute,array('someRoute','id'=>$data->id,'first'=>$this->first->id))
}

CActiveDataProvider 有一个方法 getData(),它返回所有活动记录的数组。

  1. 行动指数
$dataProvider = $model->search()
$data = $dataProvider->getData();
$this->first = reset($data );
$this->last = end($data);
  1. 最后在你看来
array(
         'name' => 'msg',
         'value' => array($this,'renderMailViewLink'),
         'type' => 'raw',
         'header' => 'Message',
     ), 

请注意,此代码未经测试。但这就是它的实现方式

于 2015-04-13T09:34:50.103 回答