Yii Framework Forum: CGridView - Yii Framework Forum

Jump to content

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

CGridView Delete from DB where ID is varchar Rate Topic: -----

#1 User is offline   Astart 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 12-February 12
  • Location:Dublin

Posted 16 April 2012 - 07:44 AM

Hi, CGridView deletes from DB properly if ID it is looking for is numeric. However, if it has letters in it, then it gives an error. Any ideas how to fix it? I believe it has to do something with csrf token validation. Any help would be appreciated.

ps I can't paste error, as for some reason it's vertical and goes beyond the screen, so I can't get all of it.

upd: nevermind the csrf part
0

#2 User is offline   Maurizio Domba 

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

Posted 16 April 2012 - 08:42 AM

CGridView only generates a delete link.. .the actual deletition is done in the actionDelete in the proper controller.. so check that method.. I assume you have something like (int)value... in that case you just need to remove the casting to int.
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   Astart 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 12-February 12
  • Location:Dublin

Posted 16 April 2012 - 09:05 AM

Upd: Just figured out it had nothing to do with CRSF token, sorry for confusion. But problem is still there

PK of the row is "00221917181E", of type varchar(20)

Here's my delete action, it's the default one that is generated by gii:
public function actionDelete($id)
	{
		if(Yii::app()->request->isPostRequest)
		{
			// we only allow deletion via POST request
			$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'));
		}
		else
			throw new CHttpException(400,'Invalid request. Please do not repeat this request again.');
	}


and the load model method, also default one:
public function loadModel($id)
	{
		$model=Device::model()->findByPk($id);
		if($model===null)
			throw new CHttpException(404,'The requested page does not exist.');
		return $model;
	}


CGrid, in case you need it as well:
$this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'device-grid',
	'dataProvider'=>$model->search(),
	'filter'=>$model,
	'columns'=>array(
		'deviceID',
		'type',
		array(
			'class'=>'CButtonColumn',
		),
	),
));

0

#4 User is offline   Astart 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 13
  • Joined: 12-February 12
  • Location:Dublin

Posted 16 April 2012 - 09:33 AM

Solved. Was my own mistake, was using old version of code. Would have noticed earlier if error was showing correctly.
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