Need help to understand how CHtml::linkButton wok for confirmation dialog

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.

Doesn’t a link button send params via POST?

Yes, correct.

I have been try to change the action to :


public function actionDeleteTableA()

        {

                if(Yii::app()->request->isPostRequest) //notice the change

                {

                   $this->loadTableA()->delete();

                   $this->redirect(--to certain page--);

                }

                else

                        throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');

        }

but still not work, the above code logic is if i send/post then do delete.

Perhaps my understanding about _POST is different, can anyone explain?

Thank You.

Try this (with the _GET version of your action):




<?php echo CHtml::linkButton('Delete',array(

			  'submit'=>$this->createUrl('DeleteTableA',array('command'=>'delete','key'=>$model->key)),

			  'confirm'=>"Are you sure want to delete this data ?")); ?>



Hey thank you your suggestion work like i hope for :D