2011-12-21 107 views
4
class Ef_AppSecurity extends Zend_Controller_Plugin_Abstract 
{ 
    public function preDispatch(Zend_Controller_Request_Abstract $request) 
    { 
     if (!Zend_Auth::getInstance()->getIdentity()) 
     { 
      $redirect = new Zend_Controller_Action_Helper_Redirector(); 
      $redirect->gotoSimpleAndExit('login', 'auth'); 
     } 
    } 
} 

它重定向並更改爲新的url,但在瀏覽器中它會創建一個重定向循環。我想知道如果問題可能來自Apache的mod_rewrite設置。Zend Framework在前端控制器插件重定向導致重定向循環

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} -s [OR] 
RewriteCond %{REQUEST_FILENAME} -l [OR] 
RewriteCond %{REQUEST_FILENAME} -d 
RewriteRule ^.*$ - [NC,L] 
RewriteRule ^.*$ index.php [NC,L] 

回答

6

不要追加對插件登錄/ AUTH,;將標準擴展爲

if (!Zend_Auth::getInstance()->getIdentity() 
    && $this->getRequest()->getControllerName() != 'login' 
    && $this->getRequest()->getActionName() != 'auth') 
+0

非常感謝chelmertz的幫助! – eforth 2011-12-21 23:52:17

+0

@eforth高興我可以幫忙!隨意將任何答案標記爲「正確」,使「案件關閉」。 – chelmertz 2011-12-22 17:37:44

0

您必須爲登錄頁面添加例外。否則,它將被重定向,並返回到本身導致循環。

因此,如果您的登錄頁面位於名爲「登錄」和「索引」操作的控制器中,則需要爲該頁面和任何其他頁面添加可能處理該窗體的異常。

if (!Zend_Auth::getInstance()->getIdentity() 
     && $this->getRequest()->getControllerName() != 'login' 
     && $this->getRequest()->getActionName() != 'index') 
     ) 
    { 
     $redirect = new Zend_Controller_Action_Helper_Redirector(); 
     $redirect->gotoSimpleAndExit('login', 'index'); 
    } 
+0

Isn'這正是我發佈的?除了你的行爲錯誤。 – chelmertz 2011-12-21 12:38:58

+0

感謝paulrichards19爲我解釋爲什麼我得到循環。 – eforth 2011-12-21 23:55:51