Recently i have problem with ‘delete’ command that generate by CRUD operation. My certain item wont delete, since i change the default controller. To solve this problem i create new function that delete data, reading from _GET[‘key’] that send from view.
Here the example link in view:
CHtml::link('Delete',array('DeleteTableA','key'=>$model->key,'command'=>'delete'));
and action for DeleteTableA :
public function actionDeleteTableA()
{
if($_GET['command']=='delete')
{
$this->loadTableA()->delete();
$this->redirect(--to certain page--);
}
else
throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
}
Above work perfectly for me, my data got delete and after deleting the page redirect to intended page.
Now my problem is, above code is based on link. There is no ‘warning’ dialog when deleting data since it use link.
My idea to show ‘warning’ dialog was using CHtml::linkButton, i need to ‘link’ CHtml::linkButton so that every time CHtml::linkButton is called its point to actionDeleteTableA().
but i dont know how to do that??
I have try to change submit, and param but its still not work.
here my failed CHtml::linkButton code :
<?php echo CHtml::linkButton('Delete',array(
'submit'=>Yii::app()->request->baseUrl.'/index.php/DeleteTableA',
'params'=>array('command'=>'delete','key'=>$model->key),
'confirm'=>"Are you sure want to delete this data ?")); ?>
emptying submit not work, but direct link to data that will delete work example
'submit'=>Yii::app()->request->baseUrl.'/index.php/DeleteTableA/key/1234',
Or i should using different solution?? If yes what you will suggest??
Thank You.