In Cgridview, it seems that I can’t use CHtml::link like usual, and we must use Yii::app()->createUrl(). I would like to build a function similar to delete but just to change field value of the model. And I wanna use Ajax with POST method.
The following only works with GET method:
array(
'header' => 'Commands',
'class' => 'CButtonColumn',
'template' => '{update}{view}{trash}{delete}',
'buttons' => array
(
'update' => array
(
'update' => 'update',
'imageUrl' => Yii::app()->request->baseUrl . '/images/edit.gif',
),
'view' => array
(
'view' => 'view',
'imageUrl' => Yii::app()->request->baseUrl . '/images/details.png',
),
'trash' => array(
'view' => 'trash',
'label' => 'Trash',
'imageUrl' => Yii::app()->request->baseUrl . '/images/recyclebin.png',
'url' => 'Yii::app()->createUrl("user/trash", array("userId" => $data->userId))',
),
'delete' => array
(
'delete' => 'delete',
'imageUrl' => Yii::app()->request->baseUrl . '/images/delete.gif',
),
),
),
public function actionTrash($id) {
if (Yii::app()->request->isPostRequest) {
$model = User::model()->findByAttributes(array('userId' => $id));
$model->isDeleted = 1;
$model->save(false);
// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
if (!isset($_GET['ajax']))
$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('index'));
}
else
throw new CHttpException(400, 'Invalid request. Please do not repeat this request again.');
}
Is there anyway can I use st like:
'url' => 'Yii::app()->createUrl("user/trash", array("type" => "post","confirm"=>"Are you sure you want to trash this item?"))' ,