Yii Cgrid View Button

I have implemented the delete functionality of Yii Cgrid view button.But Similarly Update doesn’t work.It gives me the error message

400,‘Invalid request. Please do not repeat this request again.’

Meaning the value submitted is through GET not POST.So,why did the delete button work for me?

In general the delete action should be done by POST and the update action should be done by GET. The default generated Yii code in the delete action checks if the parameter are sent with POST, but in the update action there is no check for this… did you add it ?

Thank you for the suggestion.So,can you provide me any thing on how to use the Update feature of Cgrid view button.Also,please ask me for the code if you want.

I did ask you if you changed something in your action update that is called by the update button…

Let me reply you with my snippet

My action delete function in the controller.




public function actionDelete($id)

	{

	if(Yii::app()->request->isPostRequest)

	{

	

	$a=A::model()->findByPk($id);

	$a->delete();


	if(!isset($_GET['ajax']))

    	$this->redirect(array('index','id'=>$id));

	}

	else

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

	}



My action Update in the controller




public function actionUpdate($id)

	{

	if(!Yii::app()->request->isPostRequest)

	{

	

	$a=A::model()->findByPk($id);




        if(isset($_GET['ajax']))

    	$this->redirect(array('index','id'=>$id));


	$this->render('view',array(

			'b'=>$b

		));

}


	else

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

	}



Only here after submitting the view page which is rendered it gives me the above exception(400).

Exactly… did you read your actionUpdate code?

The first line is

[color=#1C2837][size=2]


if(!Yii::app()->request->isPostRequest)

[/size][/color]

[color=#1C2837][size=2]

[/size][/color]

[color=#1C2837][size=2]and as the update is a GET and not a POST you get that error, j[/size][/color][color=#1C2837][size=2]ust remove this check ;)[/size][/color]

No I did it deliberately,because it gives me an exception.But in my case it enters into the first if block…SO,Please help me in solving this GET and POST conundrum.

Ah, right you set there the ! (not) - didn’t notice it…

OK, but in any case that line is not needed so remove it regardless…

Please post your update button configuration - what is it’s URL i.e. the URL that gets called when you press the button?

‘updateButtonUrl’=>‘Yii::app()->controller->createUrl(“update”,array(“id”=>$data->id))’

Waiting anxiously for your reply…

The link seems OK… could be that your PK (id) is not an integer?

No Sir,that was not the case.The problem was a conflict between $_POST and $_GET.Thank you for your suggestions :) :D