views:

34

answers:

2

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:

    $config = 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?

A: 

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

Todd Moses
Hm, sorry, that didnt seem to work, if I change that line in the ini file to make it look like you suggested, I get a Zend_Config_Exception with the message "syntax error, unexpected '(". Thanks for the hint though.
Max
A: 

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');
Ashley
Good idea, but that didnt change anything, unfortunately. Very strange...
Max
Have you tried var_dump-ing the contents of $routes before adding them?
Ashley