views:

71

answers:

2

I have defined 2 custom routes. One for threads/:id/:name and the other for threads/tags/:tagName however the second one conflicts with the first because if I enable both then the first breaks and treats :id literally as an action, not obeying the \d+ requirement ( I also tried using pure regex routes, see bottom ).

Action "1" does not exist and was not trapped in __call()

I tried re-arranging the order of the routes but if I do that then the threads/tags/:tagName doesnt correctly capture the tagName.

I also tried disabling default routes but the routes still don't properly work after that.

Here's my route init function:

protected function _initRoutes() {
$fc = Zend_Controller_Front::getInstance();
$router = $fc->getRouter();



$router->addRoute(
    'threads',
    new Zend_Controller_Router_Route('threads/:id/:name',
    array(
        'controller' => 'threads',
        'action'     => 'thread',
    ),
    array(
        'id' => '\d+'
    )
    )
);


$router->addRoute(
    'threads',
    new Zend_Controller_Router_Route('threads/tags/:tagName',
    array(
        'controller' => 'threads',
        'action'     => 'tags',
    ),
    array(
        'tagName' => '[a-zA-Z]+'
    )
    )
);


}

I also tried using a pure regex route but was unsuccessful, most likely because I did it wrong:

$router->addRoute(

    'threads',

    new Zend_Controller_Router_Route_Regex(
    'threads/(\d+)/([a-zA-Z]+)',
    array(
        'controller' => 'threads',
        'action'     => 'thread',
    ),
    array(
        1 => 'tagName',
        2 => 'name'
    )
    )
);
A: 

Solved.

Ah, silly me. The first argument to addRoute needs to be a unique name, and doesn't correspond directly to the controller as I assumed.

Thanks to d__asmoka, lutinvert on #zftalk. I'll accept this as soon as I can ( minimum is 2 days ).

meder
+1  A: 

Hey meder this is John get back to me ASAP via aim! I've been trying to reach you for the past one week.

John