错误 400 删除记录的无效请求 YII [英] Error 400 Invalid request YII for deleting a record
问题描述
我正在尝试删除 Yii 中的记录,这会引发错误 400.请不要再次重复此请求.它正在检查 post 变量,我的控制器文件有
if(Yii::app()->request->isPostRequest)
当我回显我的 post 变量时,它是空白而 $_GET 有我想删除的 id,我的视图文件看起来像,
I am trying to delete a record in Yii, which throws a Error 400. Please do not repeat this request again. It's checking for a post variable, my controller file has
if(Yii::app()->request->isPostRequest)
When I echo my post variable it's blank whereas $_GET has the id which I want to delete, my View file looks like,
echo CHtml::link(CHtml::encode('Delete image'), array('image/delete', 'id'=>$image->id), array('class' => 'delete','confirm'=>'This will remove the image. Are you sure?'));
访问规则已经删除到经过身份验证的用户,这是正确的.也用 * 试过了.我也尝试将其作为隐藏变量发送,但效果不佳.
The access rules has delete to authenticated users, which is right. Tried it with a * too. I also tried sending it as a hidden variable but no good.
无法弄清楚我应该如何在 Yii 中发布表单.
Not able to figure out how should I post a form in Yii.
推荐答案
发生这种情况是因为它不是发布请求.CHtml::link
有一种方法可以使用 post 方法,而不是 get.这需要您使用 clientChange
的 submit
属性>,在你的 htmlOptions
中.
This is happening because it's not a post request. CHtml::link
has a way by which you can use post method, instead of get. This requires you to use submit
attribute of clientChange
, in your htmlOptions
.
有点像这样:
echo CHtml::link(CHtml::encode('Delete image'), array('image/delete', 'id'=>$image->id),
array(
'submit'=>array('image/delete', 'id'=>$image->id),
'class' => 'delete','confirm'=>'This will remove the image. Are you sure?'
)
);
这篇关于错误 400 删除记录的无效请求 YII的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!