私はこの素晴らしい記事http://weerophinney.net/matthew/archives/246-Using-Action-Helpers-To-Implement-Re-Usable-Widgets.htmlに従いましたが、現在、単純化された例ではうまくいきません。
問題 preDispatchが読み込まれません。
新しいモジュールuserを作成しました (コントローラーUserControllerもあります。これで読み込みが台無しにならないことを願っています)。
userに 2 つのファイルを追加しました。
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()
);
}
/user/helpers およびクラス 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 ?>