Как установить видимость TbButtonColumn в зависимости от поля базы данных?

Как сделать мой TbButtonColumn невидимым на основе поля базы данных? Мои кнопки расположены внутри CGridView. Кнопки должны быть скрыты, если определенное поле пусто. Но я не могу заставить это работать. Может кто-нибудь мне помочь? Спасибо! Вот мои коды:

cGridViewPending.php

'class'=>'bootstrap.widgets.TbButtonColumn',
'template'=>'{updateView}{updateView2}',
'buttons'=>array(
'updateView'=>
array(
'url'=>'$this->grid->controller->createUrl("SendEmail", array("id"=>$data["id_schedule"]))',
'label'=>'Approve',
'visible'=>$this->fetchRemarks(), //this is where I am calling the function to hide the button.
'click'=>'function(){return confirm("Are you sure you want to approve this reservation? It is highly recommended to put a remark before approving this reservation request.");}',
'options' => array (
'class'=>'btn btn-medium btn-success',
'icon'=>'icon-circle-arrow-right',
),
),

ScheduleController.php

public function fetchRemarks()
{
$id = Yii::app()->request->getQuery('id');
$dataModel = Schedule::model()->findByPk($id);

//Remarks
$checkRemarks = "SELECT remarks FROM schedule WHERE id_schedule = $dataModel;
$x = Yii::app()->reservation_db
->createCommand($checkRemarks)
->queryScalar();

if ($x = null)
{
return false;
}
}

РЕДАКТИРОВАТЬ:
Решено! Благодаря крошечному байту! Вот как я это сделал, ради других, которые столкнутся с той же проблемой.

'url'=>'$this->grid->controller->createUrl("SendEmail", array("id"=>$data["id_schedule"]))',
'label'=>'Approve',
'visible'=>function($row_number, $model){
if ($model->remarks == 0) //the 'remarks' is my basis for the visibility of the TbButtonColumn.
{
return false;
}
else
{
return true;
}
},

0

Решение

'updateView'=>
array(
'url'=>'$this->grid->controller->createUrl("SendEmail", array("id"=>$data["id_schedule"]))',
'label'=>'Approve',
'visible'=>function($row_number, $data){ // $data is your model record

// here check whether to show the button or not
return false; //not show this button
},
2

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector