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.
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.
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;
}