2011-07-28 146 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加载模块资源在转向寻找模块引导类。“这正是我需要的。 –

相关问题