我当前的 Zend Framework 应用程序有问题.
I have a problem in my current Zend Framework application.
在我的 Bootstrap 中,我注册了这些路由:
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);
}
现在我将 Zend_Navigation 添加到我的项目中.我有几个模块,它们在模块引导程序中注册导航元素:
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);
}
}
当我在浏览器中打开应用程序时,一切正常.这意味着我可以看到导航并单击其链接以查看指定页面.但是当我点击一个使用 :module/:action/:id 路由的页面时,导航助手会抛出一个 Zend_Controller_Router_Route 异常:
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:
致命错误:Zend_Controller_Router_Exception: id is not specified in C:Entwicklungkt runksrclibraryendViewHelperNavigationHelperAbstract.php 第 519 行
Fatal error: Zend_Controller_Router_Exception: id is not specified in C:Entwicklungkt runksrclibraryendViewHelperNavigationHelperAbstract.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.
谢谢!
我自己找到了解决方案.
I found the solution myself.
这个问题是由于 Zend_Navigation 元素的一个不那么有利的行为引起的.在他们的 getHref() 方法中,他们使用了 URL 助手.此帮助程序创建导航条目必须链接到的 URL,采用为导航元素(模块、控制器、操作等)指定的参数.
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"
您遇到的问题是,当使用此路由时,URL 帮助程序使用该路由生成导航条目的链接.但是,我没有传递额外的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.
因此,一种解决方案是为每个 Zend_Navigation_Page_Mvc 实例路由"传递一个附加参数,该参数设置为默认".
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"
但我不知道您是否有能力使用 Zend Framework 做到这一点.
But I don't know if you have the ability with Zend Framework to do that.
这篇关于Zend_Controller_Router_Exception:“xyz";未指定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!