問題描述
我當前的 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模板網!