【问题标题】:Multiple actions triggered from navigation.xml从 navigation.xml 触发的多个操作
【发布时间】:2012-05-03 08:12:37
【问题描述】:

导航 xml 有一个奇怪的问题,这是一个 sn-p:

...
<registration>
      <label>Registration</label>
      <module>mine</module>
      <controller>registration</controller>
      <pages>
          <register>
             <label>Register</label>
             <module>mine</module>
             <controller>registration</controller>
             <action>doregistration</action>
           </register>
      </pages>
</registration>
...

每次我们调用 /mine/registration/index 操作时,都会触发 /mine/registration/doregistration 操作(调试时可能需要一两秒)

/mine/registration/index 确实显示正确。

此问题在整个应用程序中都会出现。 当我们改变第二个(或子)页面的动作时,这个特定的动作就会被执行。

这是 Zend 中的一个已知问题吗?以前有人遇到过这个问题吗?

【问题讨论】:

  • 这是一个很难回答的问题,它可能涉及很多方面。如果它在页面加载成功之后发生,那么我建议您查看您的 javascript。您不会从您的视图脚本中调用其他操作吗?
  • 我们没有采取行动,无处可去。事实上,我们对动作的名称进行了项目搜索,除了导航 xml 中的出现之外,我们几乎没有发现任何内容。这就是我们发现xml以某种方式参与的方式。当我们在没有 javascript(在 firefox 中禁用)的情况下运行应用程序时,我们会得到相同的行为。

标签: php zend-framework zend-navigation


【解决方案1】:

也许这个例子,来自同一个应用程序,同样的问题,让事情更清楚:

在navigation.xml:

...
<over>
    <label>Over ons</label>
    <module>default</module>
    <controller>over</controller>
    <action>index</action>
    <pages>
        <wat>
            <label>Wat?</label>
            <module>default</module>
            <controller>over</controller>
            <action>wat</action>
        </wat>
        <wie>
            <label>Wie?</label>
            <module>default</module>
            <controller>over</controller>
            <action>wie</action>
        </wie>
        <contact>
            <label>Contact</label>
            <module>default</module>
            <controller>over</controller>
            <action>contact</action>
        </contact>
        <faq>
            <label>Help</label>
            <module>default</module>
            <controller>over</controller>
            <action>faq</action>
        </faq>
    </pages>
</over>
...

对应的OverController如下所示:

class Default_OverController extends Custom_Controller_Action_EhcAction
{

public function indexAction()
{
    return $this->render('index');
}

public function contactAction()
{
    return $this->render('contact');
}

public function wieAction()
{
    return $this->render('wie');
}

public function watAction()
{
    return $this->render('wat');
}

public function faqAction()
{
    return $this->render('faq');
}
}

如您所见,我们的控制器扩展了Custom_Controller_Action_EhcAction。 这是一个自定义类,它扩展了Zend_Controller_Action 并添加了一些额外的功能(日志记录、登录用户的身份......)。这个自定义类不可能是我们问题的原因,如果我们不使用它仍然会发生。

在本例中,如果我们转到default/over/wat 操作,应用程序还将调用以下节点default/over/wie。如果我们在 XML 中切换位置,结果是第二个调用始终是下一个或第一个底层节点。

我们认为他们不是 JavaScript 调用,因为如果我们检查与 Charles 的流量,只会调度一个调用。

本示例的视图脚本仅包含简单的 HTML,没有任何 PHP 或 JS...

希望这将使我们的问题更加清晰......

【讨论】:

    【解决方案2】:

    啊哈! 我们找到了问题的原因:链接导航助手 http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.navigation.links

    我们仍然没有真正的解决方案,但这些头部链接并不那么重要。我们不再使用它了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-01
      • 2016-09-05
      • 2020-12-02
      • 2017-10-03
      • 1970-01-01
      相关资源
      最近更新 更多