Zend_Controller_Router_Exception:“xyz”没有指定 [英] Zend_Controller_Router_Exception: "xyz" is not specified

查看:153
本文介绍了Zend_Controller_Router_Exception:“xyz”没有指定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在我的Bootstrap中我注册了这些路由:

  protected function _initRouter()
{
$ this-> bootstrap(FrontController);
$ frontController = $ this-> getResource(FrontController);

$ route = new Zend_Controller_Router_Route(
:module /:id,
array(
controller=>index,
action=>index
),
array(id=>\d +)
);
$ frontController-> getRouter() - > addRoute('shortcutOne',$ route);

$ route = new Zend_Controller_Router_Route(
:module /:controller /:id,
array(action=>index),
array(id=>\d +)
);
$ frontController-> getRouter() - > addRoute('shortcutTwo',$ route);

$ route = new Zend_Controller_Router_Route(
:module /:controller /:action /:id,
null,
array(id=> \d +,action=>\w +)
);
$ frontController-> getRouter() - > addRoute('shortcutThree',$ route);
}

现在我将Zend_Navigation添加到我的项目中。我有几个模块,在模块引导中注册导航元素:$ / $ $ $ $ $ $ $ $ $ $类Contact_Bootstrap扩展Zend_Application_Module_Bootstrap
{
protected function _initNavigation()
{
$ layout = $ this-> getApplication() - > getResource(layout);
$ view = $ layout-> getView();

$ config = new Zend_Config_Xml(dirname(__ FILE __)。/ config / navigation.xml,nav);

$ view-> navigation() - > addPage($ config);
}
}

当我在浏览器中打开应用程序时,一切正常。这意味着我可以看到导航并点击其链接来查看指定的页面。但是当我打了一个使用:module /:action /:id路由的页面时,导航助手会抛出一个Zend_Controller_Router_Route异常:


致命错误:Zend_Controller_Router_Exception:不在C:\Entwicklung\kt\trunk\src\library\Zend\View\Helper\Navigation\HelperAbstract.php第519行上指定id


有没有人遇到这个错误?如果你能帮助我或给我建议,那将是很棒的。另外,如果您需要更多有关我的设置的信息等等,请告诉我。



谢谢!

解决方案

我自己找到了解决方案。



这个问题是由于Zend_Navigation元素不太有益的行为造成的。在他们的getHref()方法中,他们使用URL帮助器。这个帮助器创建导航条目链接到的URL,接受为导航元素(模块,控制器,操作等)指定的参数。



现在,问题是,如果您已经在自举程序中创建了自定义路径,就像我一样,例如

 :module /:控制器/:id

您遇到的问题是,当使用此路由时,URL帮助使用该路由生成导航条目的链接。然而,我没有传递一个额外的id参数,所以我得到了例外。



所以一个解决方案是传递每个Zend_Navigation_Page_Mvc实例路由的附加参数这被设置为默认。



我还没有尝试的另一个解决方案是让新的自定义路由将其自身重新映射到默认路线,如:

 :module /:controller /:action / id / $ id

但我不知道你是否有能力使用Zend Framework来做到这一点。


I have a problem in my current Zend Framework application.

In my Bootstrap I register these routes:

protected function _initRouter()
{
    $this->bootstrap("FrontController");
    $frontController = $this->getResource("FrontController");

    $route = new Zend_Controller_Router_Route(
        ":module/:id",
        array(
            "controller" => "index",
            "action" => "index"
            ),
        array("id" => "\d+")
        );
    $frontController->getRouter()->addRoute('shortcutOne', $route);

    $route = new Zend_Controller_Router_Route(
        ":module/:controller/:id",
        array("action" => "index"),
        array("id" => "\d+")
        );
    $frontController->getRouter()->addRoute('shortcutTwo', $route);

    $route = new Zend_Controller_Router_Route(
        ":module/:controller/:action/:id",
        null,
        array("id" => "\d+", "action" => "\w+")
        );
    $frontController->getRouter()->addRoute('shortcutThree', $route);
}

Now later I added Zend_Navigation to my project. I have several modules, that register navigation elements in the module bootstrap:

<?php

class Contact_Bootstrap extends Zend_Application_Module_Bootstrap
{
    protected function _initNavigation()
    {
        $layout = $this->getApplication()->getResource("layout");
        $view = $layout->getView();

        $config = new Zend_Config_Xml(dirname(__FILE__)."/config/navigation.xml", "nav");

        $view->navigation()->addPage($config);
    }
}

When I open the app in my browser everything works fine. That means I can see the navigation and click on its links to view the specified page. But when I hit a page that uses the :module/:action/:id route, the Navigation Helper throws a Zend_Controller_Router_Route exception:

Fatal error: Zend_Controller_Router_Exception: id is not specified in C:\Entwicklung\kt\trunk\src\library\Zend\View\Helper\Navigation\HelperAbstract.php on line 519

Did anyone of you experience this error too? It would be great if you could help me or give me advise. Also if you need more information on my setup etc., just tell me.

Thank you!

解决方案

I found the solution myself.

This problem was caused due to a not-so-beneficial behavior of the Zend_Navigation elements. In their getHref() method they use the URL helper. This helper creates the URL the navigation entry has to link to, taking in the arguments specified for the navigation element (module, controller, action, etc.)

Now, the problem is that, if you have created a custom route in your bootstrap just as I did, for example

":module/:controller/:id"

You run into the problem that when this route is being used, the URL helper uses that route to generate the link for the navigation entry. However, I did not pass on an additional "id" parameter, so I got the exception.

So one solution is to pass an additional parameter for each Zend_Navigation_Page_Mvc instance "route" which is set to "default".

Another solution, which I didn't try yet, is to let the new custom route just re-map itself onto the default route, like:

":module/:controller/:action/id/$id"

But I don't know if you have the ability with Zend Framework to do that.

这篇关于Zend_Controller_Router_Exception:“xyz”没有指定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆