Yii Framework Forum: Yii Cgrid View Button - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Yii Cgrid View Button Update Button Rate Topic: -----

#1 User is offline   YearningForYii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 21-September 12

Posted 24 January 2013 - 01:42 AM

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?
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,355
  • Joined: 12-October 09
  • Location:Croatia

Posted 24 January 2013 - 02:50 AM

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 ?
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   YearningForYii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 21-September 12

Posted 24 January 2013 - 03:21 AM

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.

View PostMaurizio Domba, on 24 January 2013 - 02:50 AM, said:

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 ?

0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,355
  • Joined: 12-October 09
  • Location:Croatia

Posted 24 January 2013 - 03:38 AM

I did ask you if you changed something in your action update that is called by the update button... Posted Image
Find more about me.... btw. Do you know your WAN IP?
0

#5 User is offline   YearningForYii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 21-September 12

Posted 24 January 2013 - 04:01 AM

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).


0

#6 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,355
  • Joined: 12-October 09
  • Location:Croatia

Posted 24 January 2013 - 04:37 AM

Exactly... did you read your actionUpdate code?

The first line is

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



and as the update is a GET and not a POST you get that error, just remove this check ;)
Find more about me.... btw. Do you know your WAN IP?
0

#7 User is offline   YearningForYii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 21-September 12

Posted 24 January 2013 - 05:07 AM

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.


View PostMaurizio Domba, on 24 January 2013 - 04:37 AM, said:

Exactly... did you read your actionUpdate code?

The first line is

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



and as the update is a GET and not a POST you get that error, just remove this check ;)

0

#8 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,355
  • Joined: 12-October 09
  • Location:Croatia

Posted 24 January 2013 - 05:12 AM

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?
Find more about me.... btw. Do you know your WAN IP?
0

#9 User is offline   YearningForYii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 21-September 12

Posted 24 January 2013 - 05:17 AM

'updateButtonUrl'=>'Yii::app()->controller->createUrl("update",array("id"=>$data->id))'

View PostMaurizio Domba, on 24 January 2013 - 05:12 AM, said:

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?

0

#10 User is offline   YearningForYii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 21-September 12

Posted 28 January 2013 - 12:34 AM

Waiting anxiously for your reply......


View PostYearningForYii, on 24 January 2013 - 05:17 AM, said:

'updateButtonUrl'=>'Yii::app()->controller->createUrl("update",array("id"=>$data->id))'

0

#11 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,355
  • Joined: 12-October 09
  • Location:Croatia

Posted 28 January 2013 - 09:00 AM

The link seems OK... could be that your PK (id) is not an integer?
Find more about me.... btw. Do you know your WAN IP?
0

#12 User is offline   YearningForYii 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 63
  • Joined: 21-September 12

Posted 30 January 2013 - 03:18 AM

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


View PostMaurizio Domba, on 28 January 2013 - 09:00 AM, said:

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

0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users