why is my route defined in a .ini file not working?
In my Bootstrap.php
I have the following code which defines a route:
$router = Zend_Controller_Front::getInstance()->getRouter();
$router->addRoute('pageDetails', new Zend_Controller_Router_Route('page-details/:uid/:title', array(
'module' => 'default',
'controller' => 'list',
'action' => 'detail',
), array(
'uid' => '\d+',
'title' => '(.*)?',
)));
This works.
Then I tried to change the route setup to using a .ini
file where the routes are defined. The .ini
file looks like this:
[routes]
pageDetails.route = "page-details/:uid/:title"
pageDetails.default.module = "default"
pageDetails.default.controller = "list"
pageDetails.default.action = "detail"
pageDetails.reqs.uid = "\d+"
pageDetails.reqs.title = "(.*)?"
And I add the routes in Bootstrap.php
via:
$conf开发者_开发百科ig = Zend_Registry::get('config');
$router = Zend_Controller_Front::getInstance()->getRouter();
$router->addConfig(new Zend_Config_Ini($config['routes']['configPathname'], 'routes'));
Although the .ini
version and the route defined in PHP code should do exactly the same, the .ini
version does not work. There is no error message in the frontend, the links look allright but on clicking a link with this route I just get redirected to the start page.
What is missing?
Try adding the prefix 'routes' to them, as in the docs:
[routes]
routes.archive.route = "archive/:year/*"
routes.archive.defaults.controller = archive
routes.archive.defaults.action = show
routes.archive.defaults.year = 2000
routes.archive.reqs.year = "\d+"
Then try this:
$config = Zend_Registry::get('config');
$routes = new Zend_Config_Ini($config['routes']['configPathname'], 'routes')
Zend_Controller_Front::getInstance()->getRouter()->addConfig($routes, 'routes');
You cannot use {}|&~![()^"
characters in the key and you have to double-quote the string for the value if you use these characters.
So double quote:
pageDetails.reqs.title = ""(.*)?""
For more on this see: http://php.net/manual/en/function.parse-ini-file.php
精彩评论