2011-12-21 20 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

ログイン/認証、またはにそのプラグインを追加しないでください。条件を延長する

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

多くのおかげでchelmertzが助けになりました! – eforth

+0

@eforth私は助けることができてうれしい!どのような答えも「正しい」とマークして、「ケースを閉じた」ようにしてください。 – chelmertz

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

これはまさに私が投稿したものですか?あなたは行動が間違っていることを除いて。 – chelmertz

+0

なぜ私はループを得ていたのかについての説明のためにpaulrichards19に感謝します。 – eforth

関連する問題