当我试图删除帖子时,我收到此错误:
Yii Error 400 The CSRF token could not be verified
Run Code Online (Sandbox Code Playgroud)
我不知道究竟是什么造成了这种情况以及它可能与之相关.这是我的动作删除:
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);
}
Run Code Online (Sandbox Code Playgroud)
小智 20
我有同样的问题,但以下解决了它.希望能帮助到你.我补充道
'params'=> array('YII_CSRF_TOKEN' => Yii::app()->request->csrfToken)
Run Code Online (Sandbox Code Playgroud)
到以下代码:
<?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)));
?>
Run Code Online (Sandbox Code Playgroud)
谢谢.
| 归档时间: |
|
| 查看次数: |
17742 次 |
| 最近记录: |