2010-08-24 2 views
0

인증을 확인하기 위해 컨트롤러 플러그인을 작성하려고합니다. 플러그인 클래스를 생성하고 Application 디렉토리에 Application.php를 넣고 Bootstrap.php에 등록했습니다. 하지만 오류가 있습니다 : 치명적인 오류 : '인증'클래스를 찾을 수 없습니다. 젠드 프레임 워크는 플러그인을 어디에서 찾을 수 있습니까?Zend Framework에서 컨트롤러 플러그인을 찾을 수없는 이유

//Application/Authentication.php 
class Authentication extends Zend_Controller_Plugin_Abstract 
{ 
    public function preDispatch(Zend_Controller_Request_Abstract $request) 
    { 
     $auth = Zend_Auth::getInstance(); 
     if ($auth->hasIdentity()) { 
      return; 
     } 

     self::setDispatched(false); 
     // handle unauthorized request... 
    } 
} 


     //bootstrap 
    protected function _initAutoloader() 
    { 
     $moduleLoader = new Zend_Application_Module_Autoloader(array(
     'basePath' => APPLICATION_PATH, 
     'namespace' => '')); 

     $autoLoader = Zend_Loader_Autoloader::getInstance(); 
     $autoLoader->registerNamespace('Common_'); 

     return $moduleLoader;    
    } 



    protected function _initPlugins() 
    { 
     $controller = Zend_Controller_Front::getInstance(); 
     $controller->registerPlugin(new Authentication()); 
     $controller->dispatch();   
    } 

감사합니다.

+0

가 나는 또한 사용 \t 보호 기능 _initAutoloader() \t { \t \t $ moduleLoader = 새로운 Zend_Application_Module_Autoloader (배열 ( \t \t 'basePath'=> APPLICATION_PATH, \t \t '네임 스페이스를'=> '')); \t \t \t \t $ autoLoader = Zend_Loader_Autoloader :: getInstance(); \t \t $ autoLoader-> registerNamespace ('Common_'); \t \t \t \t return $ moduleLoader; \t \t \t \t} – Oleg

+0

더 많은 정밀도를 제공하는 의견을 추가하는 대신 질문을 편집 할 수 있습니다. 질문을 수정하여 첫 번째 코드 블록을 수정할 수도 있습니다 ... –

+0

정보 주셔서 감사합니다. – Oleg

답변

0

나는 그 질문이 정말로 오래되었다는 것을 알고있다. 그러나 내가했던 것처럼 누군가 다른 사람이 우연히 만났을 때 대답을 남겨 둘 것이다. 다음은 플러그인을 등록하는 방법입니다 (버전 1.8부터 1.8까지).

ZF는 명명 표준을 따릅니다. A_B는 A/Bphp로 구문 분석합니다. 플러그인의 경우 ZF는 자동으로 "라이브러리 경로"를 조사합니다. 이는 라이브러리 (Zend 라이브러리가있는 디렉토리)를 찾습니다. 그래서 플러그인은 다음과 같아야합니다 : library/Something/Whatever.php ... 하나의 시나리오입니다. 그런 다음 application.ini에서 할 일은 추가는 다음과 같다 귀하의 경우에 번역

autoloaderNamespaces[] = "Something_" 
resources.frontController.plugins.Whatever = "Something_Whatever" 

것 :

autoloaderNamespaces[] = "Common_" 
resources.frontController.plugins.Authentication = "Common_Authentication" 

그리고이 라이브러리 구조가 있어야한다 :

library/Common/Authentication.php 

이 사람이 여기에 걸리는 데 도움이되기를 바랍니다!

게시물/질문 --Regarding

키우면가 자동로드와로드되지 때문에 키우면는 클래스 키우면을 "발견"없는 이유. 그 이유 중 하나는 이름 지정 규칙을 위반하는 것입니다 (인증 파일이 Common_ 디렉토리에 없거나 Authentication 클래스의 파일 이름이 Common_Authentication이 아님). 빠른 수정 넣어하는 것입니다 :이 addes와

//bootstrap 
    protected function _initAutoloader() 
    { 
     require_once 'Common/Authentication.php';   
    } 

는 _initPlugins()는 문제없이 실행할 수 있습니다. : 부트 스트랩에서

관련 문제