[英]How can i get first and last record id in yii CGridview?
我想要第一個和最后一個記錄ID形式$dataprovider
傳遞給gridview,我需要傳遞給此鏈接。
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',
),
public $first=null;
public $last=null;
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(),該方法返回所有活動記錄的數組。
$dataProvider = $model->search()
$data = $dataProvider->getData();
$this->first = reset($data );
$this->last = end($data);
array(
'name' => 'msg',
'value' => array($this,'renderMailViewLink'),
'type' => 'raw',
'header' => 'Message',
),
請注意,此代碼未經測試。 但這就是如何實現的
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.