2012-05-20 28 views
0

在我創建的yii站點中,我有一個網址爲http://localhost/administrator/restaurant/list ,它以列表形式顯示餐館列表以及刪除按鈕。刪除按鈕指向http://localhost/administrator/restaurant/delete/<id>Yii沒有使用CController :: redirect()函數正確重定向

我控制器的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和展示一個錯誤。我實現重定向功能的方式有什麼問題嗎?

回答

7

使用數組,而不是路由:

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

使用GET刪除是一個非常糟糕的主意,因爲瀏覽器可以預取鏈接之前,你甚至點擊它們。你應該使用POST來處理這種情況。

相關問題