When I was trying to delete a post I got this error:
Yii Error 400 The CSRF token could not be verified
I don't know what is exactly causing this and to what it could be related. here is my action delete:
    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.');
    }
    protected function afterDelete()
    {
        parent::afterDelete();
        Image::model()->deleteAll('name='.$this->id);
        Date::model()->deleteAll('tbl_show_id='.$this->id);
        Press::model()->deleteAll('tbl_show_id='.$this->id);
    }
I had the same issue but the following solved it. Hope it helps. I added
'params'=> array('YII_CSRF_TOKEN' => Yii::app()->request->csrfToken)
to the following code:
<?php
    echo CHtml::linkButton('Delete',array(
        'submit'=>$this->createUrl('delete',array('id'=>$model->id)),
        'confirm'=>"Are you sure want to delete ".$item->product->name."from the shopping cart?",
        'params'=> array('YII_CSRF_TOKEN' => Yii::app()->request->csrfToken)));
?>
Thanks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With