Zend Framework Widget 教程问题

发布于 2024-09-28 07:26:57 字数 874 浏览 4 评论 0原文

我尝试遵循本教程,但无法使其工作:

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

我按照描述做了一切,但我不知道如何使其在我的控制器中可用。我的文件系统如下所示:

- 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 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 and 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

她如夕阳 2024-10-05 07:26:57

看起来小部件插件没有在任何地方被调用。

有几件事需要检查:

  1. 您是否有该模块的 Bootstrap.php 文件

  2. 这个引导文件有_initWidgets()方法吗?

  3. 该方法是否调用:

    $widget = new Module_Widget_Name; // 它可以调用吗?
    Zend_Controller_Action_HelperBroker::addHelper($widget);

  4. 你注册了widget资源了吗?

    公共函数_initResourceLoader()
    <代码>{
    $loader = $this->getResourceLoader();
    $loader->addResourceType('helper', 'helpers', 'Helper');
    $loader->addResourceType('widget', 'widgets', 'Widget');

     返回 $loader;
    

    <代码>}

  5. application.ini 是否包含resources.modules[] = 行?

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?

﹏半生如梦愿梦如真 2024-10-05 07:26:57

你不知道。本教程的重点是创建一个独立于任何特定控制器运行的可重用小部件。当应用程序收到请求时,它将运行其调度周期并自动触发 preDispatch 上的操作助手:

现在,让我们看看动作助手本身。提醒一下,操作助手可以为 init() (每次传递到新控制器时由助手代理调用)、 preDispatch() (在执行控制器的 preDispatch() 挂钩并执行操作本身之前调用)定义挂钩和 postDispatch() (在操作和控制器的 postDispatch() 例程之后执行)。

助手将获取当前控制器(无论哪个可能适用于该请求)以获取 View 实例并使用表单对其进行配置

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文