Cgridview Update Unable To Get Values

Hi Guys,

I have a small error while updating CGridView using an activeTextField in a form. Somehow I have been getting the same error and I am unable to determine where it is sprouting it from.

Here is the code from the view




<?php 

	

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

							'id'=>'sell-item-grid',

							'dataProvider'=>$dataProviderSellItem,

							'columns'=>array(

													'id',

													'hasDemo.type',

													'sell_serial',

													'hasDemo.mtm',

													'sell_record_ref',

													'hasDemo.description',

													'hasDemo.demo_ref_no',

													array(

														'header'=>'Price',

														'name'=>'Price',

														'value'=>'CHtml::activeTextField($data,"sell_price")',

														'type'=>'raw',

														'htmlOptions'=>array('id'=>'Price',

															),

														),

													array(

															'header'=>'Action',

															'class'=>'CButtonColumn',

															'template'=>'{delete}',	

															),

													),

												));

							


 ?>

	<?php echo TbHtml::ajaxSubmitButton('submit','SellItem/itemConfirm'); ?>



Controller




public function actionItemConfirm()

	{

		

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

		{

			echo 'SELL OK';

		}

		else echo 'nothing';

	}



I am always getting the following error from Firebug

I’m not quite sure where it is pulling this id in the error from.

Any help is greatly appreciated

Show me where is 66 line, where is error?

can you dump your SellItemController code here

SellItemController here




<?php


class SellItemController extends Controller

{

	/**

	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning

	 * using two-column layout. See 'protected/views/layouts/column2.php'.

	 */

	public $layout='//layouts/column1';


	/**

	 * @return array action filters

	 */

	public function filters()

	{

		return array(

			'accessControl', // perform access control for CRUD operations

			'postOnly + delete', // we only allow deletion via POST request

		);

	}


	/**

	 * Specifies the access control rules.

	 * This method is used by the 'accessControl' filter.

	 * @return array access control rules

	 */

	public function accessRules()

	{

		return array(

			array('allow',  // allow all users to perform 'index' and 'view' actions

				'actions'=>array('index','view'),

				'users'=>array('*'),

			),

			array('allow', // allow authenticated user to perform 'create' and 'update' actions

				'actions'=>array('create','update','addSellItem','itemConfirm'),

				'users'=>array('@'),

			),

			array('allow', // allow admin user to perform 'admin' and 'delete' actions

				'actions'=>array('admin','delete'),

				'users'=>array('admin'),

			),

			array('deny',  // deny all users

				'users'=>array('*'),

			),

		);

	}


	/**

	 * Displays a particular model.

	 * @param integer $id the ID of the model to be displayed

	 */

	public function actionView($id)

	{

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

			'model'=>$this->loadModel($id),

		));

	}


	/**

	 * Creates a new model.

	 * If creation is successful, the browser will be redirected to the 'view' page.

	 */

	public function actionCreate()

	{

		

		$modelSellRecord = SellRecord::model()->findbyPk($_GET['id']);

		$modelSell = SellItem::model()->findAll('sell_record_ref=:sell_record_ref',array(':sell_record_ref'=>$modelSellRecord->sell_record_ref));


		// Uncomment the following line if AJAX validation is needed

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


		//Sell Items Table

		$criteriaSellItem = new CDbCriteria();

		//$criteriaLoanItem->with = 'hasDemo';

		//$criteriaLoanItem->with = 'hasLoanRecord';

		$criteriaSellItem->condition = 'sell_record_ref=:sell_record_ref';

		$criteriaSellItem->params = array(':sell_record_ref'=>$modelSellRecord->sell_record_ref,);

		$dataProviderSellItem = new CActiveDataProvider('SellItem', array(

																								'criteria'=>$criteriaSellItem,

																								

																								));

		//Items Table

		$criteriaItems = new CDbCriteria();

		$criteriaItems->condition = 'status =:status AND country=:country';

		$criteriaItems->params = array(':status'=>1, ':country'=>Yii::app()->user->country);

		$criteriaItems->order = 'type';

		$dataProviderItems = new CActiveDataProvider('DemoPool', array(

																			'criteria'=>$criteriaItems,

																			'pagination'=>array(

																										'pageSize'=>10,

																										)));

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

		{

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

			if($model->save())

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

		}


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

			'modelSellRecord'=>$modelSellRecord,

			'modelSell'=>$modelSell,

			'dataProviderSellItem'=>$dataProviderSellItem,

			'dataProviderItems'=>$dataProviderItems,

		));

	}


	/**

	 * Updates a particular model.

	 * If update is successful, the browser will be redirected to the 'view' page.

	 * @param integer $id the ID of the model to be updated

	 */

	public function actionUpdate($id)

	{

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


		// Uncomment the following line if AJAX validation is needed

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


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

		{

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

			if($model->save())

				$this->redirect(array('SellItem/create','id'=>$model->id));

		}


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

			'model'=>$model,

		));

	}


	/**

	 * Deletes a particular model.

	 * If deletion is successful, the browser will be redirected to the 'admin' page.

	 * @param integer $id the ID of the model to be deleted

	 */

	public function actionDelete($id)

	{

		$this->loadModel($id)->delete();


		// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser

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

			$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));

	}


	/**

	 * Lists all models.

	 */

	public function actionIndex()

	{

		$dataProvider=new CActiveDataProvider('SellItem');

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

			'dataProvider'=>$dataProvider,

		));

	}


	/**

	 * Manages all models.

	 */

	public function actionAdmin()

	{

		$model=new SellItem('search');

		$model->unsetAttributes();  // clear any default values

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

			$model->attributes=$_GET['SellItem'];


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

			'model'=>$model,

		));

	}


	/**

	 * Returns the data model based on the primary key given in the GET variable.

	 * If the data model is not found, an HTTP exception will be raised.

	 * @param integer $id the ID of the model to be loaded

	 * @return SellItem the loaded model

	 * @throws CHttpException

	 */

	public function loadModel($id)

	{

		$model=SellItem::model()->findByPk($id);

		if($model===null)

			throw new CHttpException(404,'The requested page does not exist.');

		return $model;

	}


	/**

	 * Performs the AJAX validation.

	 * @param SellItem $model the model to be validated

	 */

	protected function performAjaxValidation($model)

	{

		if(isset($_POST['ajax']) && $_POST['ajax']==='sell-item-form')

		{

			echo CActiveForm::validate($model);

			Yii::app()->end();

		}

	}


	public function actionAddSellItem()

	{

		

		$modelSellRecord = SellRecord::model()->findbyPk($_GET['SellID']);


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

			{

				foreach ($_POST['value'] as $id)

				{

					$modelDemo = DemoPool::model()->findbyPk($id);

					$model=new SellItem;

					$model->sell_serial = $modelDemo->serial;

					$model->sell_record_ref = $modelSellRecord->sell_record_ref;

					//$model->sell_price = 409;

					$model->save();

					/*$modelDemo->status = 5;

					$modelDemo->save();*/

					

				}

			}

	}


	public function actionItemConfirm()

	{

		

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

		{

			

			echo $_POST['SellItem']['sell_price'];

			//$model = SellRecord::model()->findbyPk($_POST['id']);

			//echo $model->sell_serial;

		}

		else echo 'nothing';

	}

}






I’m not sure why it is calling on Line 66 when the action being called does not require it. Maybe I am looking at this wrong?

SellItemController here




<?php


class SellItemController extends Controller

{

	/**

	 * @var string the default layout for the views. Defaults to '//layouts/column2', meaning

	 * using two-column layout. See 'protected/views/layouts/column2.php'.

	 */

	public $layout='//layouts/column1';


	/**

	 * @return array action filters

	 */

	public function filters()

	{

		return array(

			'accessControl', // perform access control for CRUD operations

			'postOnly + delete', // we only allow deletion via POST request

		);

	}


	/**

	 * Specifies the access control rules.

	 * This method is used by the 'accessControl' filter.

	 * @return array access control rules

	 */

	public function accessRules()

	{

		return array(

			array('allow',  // allow all users to perform 'index' and 'view' actions

				'actions'=>array('index','view'),

				'users'=>array('*'),

			),

			array('allow', // allow authenticated user to perform 'create' and 'update' actions

				'actions'=>array('create','update','addSellItem','itemConfirm'),

				'users'=>array('@'),

			),

			array('allow', // allow admin user to perform 'admin' and 'delete' actions

				'actions'=>array('admin','delete'),

				'users'=>array('admin'),

			),

			array('deny',  // deny all users

				'users'=>array('*'),

			),

		);

	}


	/**

	 * Displays a particular model.

	 * @param integer $id the ID of the model to be displayed

	 */

	public function actionView($id)

	{

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

			'model'=>$this->loadModel($id),

		));

	}


	/**

	 * Creates a new model.

	 * If creation is successful, the browser will be redirected to the 'view' page.

	 */

	public function actionCreate()

	{

		

		$modelSellRecord = SellRecord::model()->findbyPk($_GET['id']);

		$modelSell = SellItem::model()->findAll('sell_record_ref=:sell_record_ref',array(':sell_record_ref'=>$modelSellRecord->sell_record_ref));


		// Uncomment the following line if AJAX validation is needed

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


		//Sell Items Table

		$criteriaSellItem = new CDbCriteria();

		//$criteriaLoanItem->with = 'hasDemo';

		//$criteriaLoanItem->with = 'hasLoanRecord';

		$criteriaSellItem->condition = 'sell_record_ref=:sell_record_ref';

		$criteriaSellItem->params = array(':sell_record_ref'=>$modelSellRecord->sell_record_ref,);

		$dataProviderSellItem = new CActiveDataProvider('SellItem', array(

																								'criteria'=>$criteriaSellItem,

																								

																								));

		//Items Table

		$criteriaItems = new CDbCriteria();

		$criteriaItems->condition = 'status =:status AND country=:country';

		$criteriaItems->params = array(':status'=>1, ':country'=>Yii::app()->user->country);

		$criteriaItems->order = 'type';

		$dataProviderItems = new CActiveDataProvider('DemoPool', array(

																			'criteria'=>$criteriaItems,

																			'pagination'=>array(

																										'pageSize'=>10,

																										)));

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

		{

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

			if($model->save())

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

		}


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

			'modelSellRecord'=>$modelSellRecord,

			'modelSell'=>$modelSell,

			'dataProviderSellItem'=>$dataProviderSellItem,

			'dataProviderItems'=>$dataProviderItems,

		));

	}


	/**

	 * Updates a particular model.

	 * If update is successful, the browser will be redirected to the 'view' page.

	 * @param integer $id the ID of the model to be updated

	 */

	public function actionUpdate($id)

	{

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


		// Uncomment the following line if AJAX validation is needed

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


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

		{

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

			if($model->save())

				$this->redirect(array('SellItem/create','id'=>$model->id));

		}


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

			'model'=>$model,

		));

	}


	/**

	 * Deletes a particular model.

	 * If deletion is successful, the browser will be redirected to the 'admin' page.

	 * @param integer $id the ID of the model to be deleted

	 */

	public function actionDelete($id)

	{

		$this->loadModel($id)->delete();


		// if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser

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

			$this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));

	}


	/**

	 * Lists all models.

	 */

	public function actionIndex()

	{

		$dataProvider=new CActiveDataProvider('SellItem');

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

			'dataProvider'=>$dataProvider,

		));

	}


	/**

	 * Manages all models.

	 */

	public function actionAdmin()

	{

		$model=new SellItem('search');

		$model->unsetAttributes();  // clear any default values

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

			$model->attributes=$_GET['SellItem'];


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

			'model'=>$model,

		));

	}


	/**

	 * Returns the data model based on the primary key given in the GET variable.

	 * If the data model is not found, an HTTP exception will be raised.

	 * @param integer $id the ID of the model to be loaded

	 * @return SellItem the loaded model

	 * @throws CHttpException

	 */

	public function loadModel($id)

	{

		$model=SellItem::model()->findByPk($id);

		if($model===null)

			throw new CHttpException(404,'The requested page does not exist.');

		return $model;

	}


	/**

	 * Performs the AJAX validation.

	 * @param SellItem $model the model to be validated

	 */

	protected function performAjaxValidation($model)

	{

		if(isset($_POST['ajax']) && $_POST['ajax']==='sell-item-form')

		{

			echo CActiveForm::validate($model);

			Yii::app()->end();

		}

	}


	public function actionAddSellItem()

	{

		

		$modelSellRecord = SellRecord::model()->findbyPk($_GET['SellID']);


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

			{

				foreach ($_POST['value'] as $id)

				{

					$modelDemo = DemoPool::model()->findbyPk($id);

					$model=new SellItem;

					$model->sell_serial = $modelDemo->serial;

					$model->sell_record_ref = $modelSellRecord->sell_record_ref;

					//$model->sell_price = 409;

					$model->save();

					/*$modelDemo->status = 5;

					$modelDemo->save();*/

					

				}

			}

	}


	public function actionItemConfirm()

	{

		

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

		{

			

			

                        echo 'OK'

		}

		else echo 'nothing';

	}

}






I’m not sure why it is calling on Line 66 when the action being called does not require it. Maybe I am looking at this wrong?

Line 66: $modelSellRecord = SellRecord::model()->findbyPk($_GET[‘id’]);

You are not providing $_GET[‘id’] here.