Yii not redirecting properly with the CController::redirect() function

醉酒当歌 提交于 2019-12-25 02:18:18

问题


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>.

The actionDelete of my controller is as follows :

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);
    }

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 ?


回答1:


Use array routing instead:

$this->redirect(array('restaurant/list'), true);

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.



来源:https://stackoverflow.com/questions/10671477/yii-not-redirecting-properly-with-the-ccontrollerredirect-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!