2011-12-01 71 views
0

我最近從CakePHP 1.2升級到CakePHP 1.3,現在我有一些代碼在重定向循環中捕獲用戶。這是用戶成功登錄後決定點擊鏈接來管理電子郵件。CakePHP從1.2升級到1.3現在提供重定向循環

我在控制器中有一些代碼,index()方法將檢查當前用戶是否是管理員。如果用戶是不是管理員將做到以下幾點:

function index() 
{ 
    if ($this->Session->read('is_admin') < 1) { 
     $this->redirect(array('controller' => 'emails', 'action' => 'view', 'id' => $this->Session->read('username'))); 
    } 

    //...more code... 
} 

這是爲了將用戶重定向到一個視圖()方法,並只顯示他們的電子郵件,而不是每個人的電子郵件。當我調試這個時發生了什麼,重定向一直在index()方法中結束。

CakePHP中有什麼新的東西我缺少?在控制器中使用名稱「視圖」作爲動作是否是否定的?

*編輯*

好吧,我是有點爲時過早這一職務。視圖($ username)方法中的代碼已到達。但是,事實是$ username沒有被定義,並且我有一些客戶端代碼,如果它沒有被定義,那麼它們會被重定向回index()動作。

我沒有檢查原來的重定向,並且$ this-> Session-> read('username')填充了用戶名,但它只是沒有在view()的$ username參數中傳遞。

謝謝!

+0

是否得到重定向?或跳過它?你的應用程序是否使用ACL?用戶是否有權訪問「查看」操作? –

+0

Hey Moz,我用更多的信息更新了我的問題。要回答你的問題,它確實得到了重定向,我的應用程序確實使用ACL,並且用戶有權訪問「視圖」操作。 – programmer

+1

由於我不能回答我自己的問題,我會在這裏回答它: 原來重定向簽名從1.2更改爲1.3: http://book.cakephp.org/view/1561/Migrating-from- CakePHP-1-2-to-012 庫類>路由器 // CakePHP 1.2路 $ this-> redirect(array('controller'=>'emails','action'=>'view',' id'=> $ this-> Session-> read('username'))); ('controller'=>'emails','action'=>'view',$ this-> Session-> read('username'))); – programmer

回答

0

原來從1.2到1.3改變了重定向簽名:

http://book.cakephp.org/view/1561/Migrating-from-CakePHP-1-2-to-1-3 庫類>路由器

// CakePHP 1.2 way 
$this->redirect(array('controller' => 'emails', 'action' => 'view', 'id' => $this->Session->read('username'))); 

// CakePHP 1.3 way 
$this->redirect(array('controller' => 'emails', 'action' => 'view', $this->Session->read('username')));