Yii Error 400 The CSRF token could not be verified when trying to delete the post
php, yii
Solution
It seems you've enabled CSRF validation. If you want to use it, read the doc and make sure you send the CSRF token in every POST request.
Problem
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); } ```