Error 400 on update and view actions

I generated a project using the yiic tool from the command line. Then I used gii to create a model and its accompanying crud operations. This table previously data. I navigated to the manage link and from the display gridview I clicked update on one record. The page loaded with error 400 your request is invalid.

My operating system is fedora 16.

my server is apache server 2.2.22

am using php 5.4.1.1

am using yii framework 1.1.10

This is the code sample




public function actionUpdate($id)

	{

		$model=$this->loadModel($id);


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['Admission']))

		{

			$model->attributes=$_POST['Admission'];

			if($model->save())

				$this->redirect(array('view','id'=>$model->pk_serial));

		}


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

			'model'=>$model,

		));

	}






<?php $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'admission-grid',

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		'pk_serial',

		'fk_person',

		'sortkey',

		'date_admn',

		'time_admn',

		'cough',

		array(

			'class'=>'CButtonColumn',

		),

	),

)); ?>



Please read the guidelines for posting on the forum - http://www.yiiframework.com/forum/index.php/topic/19451-guidelines-for-posting-this-forum/

If i pass a default parameter value the error disappears and my code picks the default value as opposed to the value on the url

Example




public function actionUpdate($id='')

	{

		$model=$this->loadModel($id);


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['Admission']))

		{

			$model->attributes=$_POST['Admission'];

			if($model->save())

				$this->redirect(array('view','id'=>$model->pk_serial));

		}


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

			'model'=>$model,

		));

	}



But if on the same action i use the $_GET[‘id’] function it will return the url value.

Example:




public function actionUpdate($id='')

	{

$id_test = $_GET['id'];




		$model=$this->loadModel($id);


		// Uncomment the following line if AJAX validation is needed

		// $this->performAjaxValidation($model);


		if(isset($_POST['Admission']))

		{

			$model->attributes=$_POST['Admission'];

			if($model->save())

				$this->redirect(array('view','id'=>$model->pk_serial));

		}


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

			'model'=>$model,

		));

	}



my url is ?r=admission/update&id=105479

therefore $id_test is assigned 105479.

Help me out on this please.

Check this part of the documentation - http://www.yiiframework.com/doc/guide/1.1/en/basics.controller#action-parameter-binding

I had exactly the same issues after trying upgrade to PHP 5.4.1. Rolled back to PHP 5.3.11 and all is good now.

I confirm that for Yii 1.1.10 on PHP 5.4.3

Any parameterized action will throw 400 Bad request in


CController->runAction(Object(CInlineAction))

Looks like it is Reflection issue: ReflectionMethod’s constructor does something mad here:





// framework/web/action/CInlineAction.php


/**

 * Runs the action with the supplied request parameters.

 * This method is internally called by {@link CController::runAction()}.

 * @param array $params the request parameters (name=>value)

 * @return boolean whether the request parameters are valid

 * @since 1.1.7

 */

public function runWithParams($params)

{

    $methodName='action'.$this->getId();

    $controller=$this->getController();

    $method=new ReflectionMethod($controller, $methodName);


    // DUMP METHOD OBJECT

    var_dump($method);exit;


    if($method->getNumberOfParameters()>0)

        return $this->runWithParamsInternal($controller, $method, $params);

    else

        return $controller->$methodName();

}



Outputs something like:





object(ReflectionMethod;:§ö)[11]

  public 'namei˜¥' => string 'actionView' (length=10)

  public 'class' => string 'BoardController' (length=15)



i have the same problem(as the first member) when i click the update thumbnail button(or any other: delete, view)not in my regular buttons, in my CRUD application

Just in case anyone comes across this issue. In my case, the issue was with the php_apc.dll extension. Once it was disabled, reflection worked properly.