开发者

Action_Helper in separte module does not get loaded

开发者 https://www.devze.com 2023-03-23 07:10 出处:网络
I followed this great article http://weierophinney.net/matthew/archives/246-Using-Action-Helpers-To-Implement-Re-Usable-Widgets.html, but currently i can\'t get work my simplified example.

I followed this great article http://weierophinney.net/matthew/archives/246-Using-Action-Helpers-To-Implement-Re-Usable-Widgets.html, but currently i can't get work my simplified example.

PROBLEM The preDispatch does not get loaded.

I created new module user (there is also controller UserController, i hope this wont mess up the loading).

I have added two files in user.

Bootstrap.php - under module user

class User_Bootstrap extends Zend_Application_Module_Bootstrap {

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

protected  function _initHelpers() {
    Zend_Controller_A开发者_如何学Cction_HelperBroker::addHelper(
        new User_Helper_HandleLogin()
    );
}

New folder under /user/helpers and class 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;
}

}

And lastly added into layout.phtml the output.

<?php echo $this->user ?>


is init() function of User_Helper_HandleLogin works? is User_Bootstrap works? :) maybe you forget resources.modules[] = in config.ini?

0

精彩评论

暂无评论...
验证码 换一张
取 消