开发者

Zend Framework Widget Tutorial question

开发者 https://www.devze.com 2023-01-21 17:43 出处:网络
I try to follow this tutorial, but I can\'t get it to work: http://weierophinney.net/matthew/archives/246-Using-Action-Helpers-To-Implement-Re-Usable-Widgets.html

I try to follow this tutorial, but I can't get it to work:

http://weierophinney.net/matthew/archives/246-Using-Action-Helpers-To-Implement-Re-Usable-Widgets.html

I did everything as described, but I don't know how to make it available in my controllers. My filesystem looks like this:

- application
    - controllers
        - IndexController.php
    - modules
        - user
            - configs
                user.ini
            - controllers
            - forms
                Login.php
            - helpers
                HandleLogin.php
            - views
                - scripts
                    login.phmtl
                    profile.phtml
            Bootstrap.php
    - views

How do I use the HandleLogin Helper in my IndexController? I really have no idea an开发者_StackOverflow社区d I'm looking an trying for more then a day and I almost want to throw my PC out of the window ;). So any help would be appreciated!


Looks like the widget plugin is not called anywhere.

Few things to check:

  1. Do you have a Bootstrap.php file for the module?

  2. Does this bootstrap file has _initWidgets() method?

  3. Does this method call:

    $widget = new Module_Widget_Name; // is it callable?
    Zend_Controller_Action_HelperBroker::addHelper($widget);

  4. Have you registered widget resource?

    public function _initResourceLoader()
    {
    $loader = $this->getResourceLoader();
    $loader->addResourceType('helper', 'helpers', 'Helper');
    $loader->addResourceType('widget', 'widgets', 'Widget');

     return $loader;
    

    }

  5. Does application.ini contains resources.modules[] = line?


You dont. The point of the tutorial is to create a reusable widget that runs independent from any specific controllers. When the application receives a request, it will run through it's dispatch cycle and trigger the action helper on preDispatch automatically:

Now, let's look at the action helper itself. As a reminder, action helpers can define hooks for init() (invoked by the helper broker each time it is passed to a new controller), preDispatch() (invoked prior to executing the controller's preDispatch() hook and executing the action itself), and postDispatch() (executed after the action and the controller's postDispatch() routine).

The helper will fetch the current controller (whichever that may be for that request) to get the View instance and configure it with the form

0

精彩评论

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