我跟着这篇文章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 ?>
是'init()'函数User_Helper_HandleLogin的工作原理?是User_Bootstrap的作品? :)也许你会在'config.ini'中忘记'resources.modules [] ='? – SMka