问题描述
限时送ChatGPT账号..在我创建的 yii 站点中,我有一个带有 url http://localhost/administrator/restaurant/list
的页面它以表格格式显示餐厅列表以及删除按钮.删除按钮指向 http://localhost/administrator/restaurant/delete/
.
In a yii site I am creating I have a page with the url http://localhost/administrator/restaurant/list
which shows the list of restaurants in a tabular format along with a delete button. The delete button points to http://localhost/administrator/restaurant/delete/<id>
.
我的控制器的actionDelete
如下:
public function actionDelete(){
$model = Restaurants::model()->findByAttributes(
array(
'id'=>$_GET['id'],
'clientId'=>Yii::app()->user->clientId
));
$model->delete();
Yii::app()->user->setFlash('success',Yii::t('error','Restaurant has been deleted successfully'));
$this->redirect('restaurant/list',true);
}
但是在单击删除按钮时,该行已从数据库中成功删除,但不是重定向到 http://localhost/administrator/restaurant/list
页面正在重定向到 http://localhost/administrator/restaurant/delete/restaurant/list
并显示错误.我实现重定向功能的方式有问题吗?
But on clicking the delete button, the row is getting deleted successfully from the database but instead of redirecting to http://localhost/administrator/restaurant/list
the page is redirecting to http://localhost/administrator/restaurant/delete/restaurant/list
and showing an error. Is there something wrong with the way I implemented the redirect function ?
推荐答案
改用数组路由:
$this->redirect(array('restaurant/list'), true);
<小时>
使用 GET 进行删除是一个非常糟糕的主意,因为浏览器甚至可以在您单击链接之前预取链接.你应该在任何这样的场景中使用 POST.
Using GET for deleting is a very bad idea because browsers can prefetch links before you even click them. You should use POST for any scenario like this.
这篇关于Yii 没有使用 CController::redirect() 函数正确重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论