2011-07-28 44 views
1

我跟着這篇文章http://weierophinney.net/matthew/archives/246-Using-Action-Helpers-To-Implement-Re-Usable-Widgets.html,但目前我無法使用我的簡化示例。Action_Helper in separte module does not get loaded

問題preDispatch沒有得到加載

我創造了新的模塊用戶(也有控制器UserController的,我希望這不會弄亂加載)。

我在用戶中添加了兩個文件。

bootstrap.php中 - 下模塊的用戶

class User_Bootstrap extends Zend_Application_Module_Bootstrap { 

public function initResourceLoader() { 
    $loader = $this->getResourceLoader(); 
    $loader->addResourceType('helper', 'helpers', 'Helper'); 
} 

protected function _initHelpers() { 
    Zend_Controller_Action_HelperBroker::addHelper(
     new User_Helper_HandleLogin() 
    ); 
} 

新建文件夾下的/用戶/護理人員和類HandleLogin。

class User_Helper_HandleLogin extends Zend_Controller_Action_Helper_Abstract { 

protected $view; 

public function preDispatch() { 
    echo 'called'; 
    if (($controller = $this->getActionController()) === null) { 
     return; 
    } 

    $this->createProfileWidget(); 
} 

public function createProfileWidget() { 
    if (!$view = $this->getView()) { 
     return; 
    } 
    $view->user = '<h2>HELLO WORLD</h2>'; 
} 

public function createLoginForm() { 

} 

public function getView() { 
    if ($this->view !== null) { 
     return $this->view; 
    } 

    $controller = $this->getActionController(); 
    $view = $controller->view; 

    if (!$view instanceof Zend_View_Abstract) { 
     return; 
    } 

    //$view->addScriptPath(dirname(__FILE__) .'/../views/scripts'); 
    $this->view = $view; 
    return $view; 
} 

}

並且最後加入layout.phtml輸出。

<?php echo $this->user ?> 
+0

是'init()'函數User_Helper_HandleLogin的工作原理?是User_Bootstrap的作品? :)也許你會在'config.ini'中忘記'resources.modules [] ='? – SMka

回答

2

init()功能User_Helper_HandleLogin的作品?是User_Bootstrap的作品? :)也許你忘了resources.modules[] =config.ini

+0

我添加了handleLogin(),但仍然存在查找和加載插件的問題。 handleLogin插件在* User * modules bootstrap中註冊,所以這應該自動加載?我不能讓單獨的帖子錯誤是致命的錯誤:未註冊的異常'Zend_Loader_PluginLoader_Exception'消息'通過名稱的'HandleLogin'插件找不到';在/ home/risto/library/Zend/Loader/PluginLoader中使用了ZendX_JQuery_View_Helper_:ZendX/JQuery/View/Helper/Zend_View_Helper_:Zend/View/Helper /:/ var/www/review/application/views/helpers /'。 php:412堆棧跟蹤:#0 –

+0

謝謝你,添加resources.modules []行,它現在的作品,唯一的解釋是我發現是從akrabat.com網站「resources.modules告訴Zend_Application加載模塊資源在轉向尋找模塊引導類。「這正是我需要的。 –

相關問題