2011-12-18 9 views
-2

컨트롤러의 한 동작에 대해서만 플러그인을 시작하는 가장 좋은 방법은 무엇입니까?젠드 프레임 워크 - 플러그인

는 보충 : 여기

코드의 조각, 나는 인 IndexController 난 당신이

을 큼직한에 대한 코드의이 작품은 도움이 될 수 있기를 바랍니다

class MyApp_Plugin_MyPlugin extends Zend_Controller_Plugin_Abstract 
{ 
    public function preDispatch(Zend_Controller_Request_Abstract $request) 
    { 
     print 'hello world'; 
    } 
} 

에 testAction이 플러그인을 실행하려면

감사합니다

+1

일부 코드는 여기에서 도움이 될뿐만 아니라 달성하려는 것에 대한 설명이 될 수 있습니다. – Zoot

답변

2

직접 플러그인을 호출 할 수 있습니다.

public function someAction() 
{ 
    // The action in the controller you want the plugin to run 

    $p = new Application_Plugin_Something(); 
    $p->doSomething(); 
} 

또는 부트 스트랩에 등록하고 무엇을 볼 수있는 플러그인 검사가 단지 올바른 모듈, "TheController"와 "TheAction"와 "기본"을 대체, 그것은 플러그인 코드에서

class Application_Plugin_Example extends Zend_Controller_Plugin_Abstract 
{ 
    public function preDispatch(Zend_Controller_Request_Abstract $request) 
    { 
     $module  = $request->getModuleName(); 
     $controller = $request->getControllerName(); 
     $action  = $request->getActionName(); 

     if ($module != 'default' && $controller != 'TheController' && $action != 'TheAction') { 
      return; 
     } 

     // plugin code here... 
    } 
} 

// in bootstrap 

Zend_Controller_Front::getInstance() 
         ->registerPlugin(
          new Application_Plugin_Example() 
         ); 

를 실행 콘트롤러와 액션으로 플러그인을 실행시키고 싶습니다.