[英]Displaying data from two tables in Yii CGridView
我想顯示帶有正確聯接的2個表,但是我編寫的代碼無法按預期工作。 誰能告訴我我做錯了什么?
查看:admin.php
$this->widget('bootstrap.widgets.TbGridView', array(
'id' => 'punish-grid',
'dataProvider' => $model->searchJoin(),
'type' => 'striped bordered condensed',
'filter' => $model,
'columns' => array(
array(
'header' => 'No',
'type'=>'raw',
'htmlOptions'=>array('style'=>'width: 25px'),
'value'=>'$this->grid->dataProvider->pagination->currentPage
*$this->grid->dataProvider->pagination->pageSize + $row+1',
),
// i want to display p.kode,p.status from table status
'berlaku_punish',
'nilai',
array(
'class'=>'bootstrap.widgets.TbButtonColumn',
),
),
));
和我的模型:BasePunish.php
public function relations() {
return array(
'idStatus' => array(self::BELONGS_TO, 'Status', 'id_status'),
);
}
public function searchJoin() {
$criteria = new CDbCriteria;
$criteria->select = 'p.kode,p.status,t.nilai,t.berlaku_punish';
$criteria->join= 'RIGHT JOIN status p ON (t.id_status=p.id)';
$criteria->condition = 't.id_status IS NULL';
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
'sort'=>array(
'defaultOrder'=>'kode ASC',
),
)
);
}
我可能真的不明白您在問什么,但是仍然沒有任何幫助,那么您可以嘗試一下
array(
'header'=>'Products',
'value'=>array($model,'gridCreateUser'),
),
在這種情況下,該值將嘗試在以$ model為對象的類中找到函數gridCreateUser 。 在您的情況下,我猜$ model是BasePunish的對象。
因此,在BasePunish.php中創建一個函數gridCreateUser() ,然后可以返回要在小部件中顯示的值。
例如:-在您的BasePunish.php中
public function gridCreateUser($data)
{
// you can access the object $data here
// do what ever you want to do
$value='return whatever you want to return';
return $value;
// this $value will be displayed there
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.