Use the default route with Zend Router by default
How can I configure Zend_Controller_Router to use the default route by default? For whatever reason unknown, it uses the current route.
This is causing some annoying routing issues, and I don't feel like editing hundreds of links to explicitly u开发者_JS百科se the default route is a reasonable solution to add one custom route.
Your question isn't obvious and is confusing, I will try though.
I am going to assume you do not mean Zend_Controller_Route
but in fact are talking about links generated in your views.
You can use baseUrl()
like this
<a href="<?=$this->baseUrl("about-us")?>">About Us</a>
You can set the baseUrl
in your Bootstrap like this
Zend_Controller_Front::getInstance()->setBaseUrl("/");
If you are working locally you may want to set it to something like this
Zend_Controller_Front::getInstance()->setBaseUrl("/my-app/public");
Using baseUrl()
in your views will now use that path to base all your URLs on. Remember you must wrap your links in baseUrl()
for this to work.
The url()
helper is not useful for this, this is used for doing things like pagination where you want the current parameters of the request object to be maintained.
Hope that helps.
From Matthew Weier O'Phinney:
The logic you quote above is within the assemble() method. assemble() may be called with or without routing having occurred. By default, the assumption is that if no route name is provided, the currently matched route is utilized -- and if matching was never performed (or no route matched), the 'default' route will be used.
The rationale for using the currently matched route is that typically you will be routing within the same schema -- as an example, if you are within a RESTful paradigm, the majority of your links will be within the current resource. If we were to follow your suggestion to utilize the "default" route when no route is specified (at least, that's how I interpret what you said), because the Rest_Route is not the default route, every single call to assemble() would require using the route name -- which others would deride as causing "headaches."
Personally, I prefer to be explicit and always specify the route name; this way I know exactly what route I'm targetting during assemble(), which makes debugging easier.
Sounds like the only solution is to set the route for each link to use 'default' instead of leaving it NULL.
精彩评论