Dmitry Z.
Dmitry Z.

Reputation: 434

Zend_Router_Regex and additional parameter

I have no idea how realize it.

I have this router

$route = new Zend_Controller_Router_Route_Regex(
                    'category/([-\w]+)(?:/(\d+))?',
                    array('module' => 'dynamic', 'controller' => 'index', 'action' => 'show-category'),
                    array(1 => 'category', 2 => 'pageNumber'),
                    'category/%s/%d'
    );

$router->addRoute('dynamic-categories', $route);

Assembled url in view will be /category/news/1 by using $this->url(...) helper. I want that my first page of news will be /category/news. Should I use other route to do it or use router chaining. I'm frustrated. Thank you for help.

Upvotes: 0

Views: 151

Answers (1)

Fge
Fge

Reputation: 2961

You can use Zend_Controller_Router_Route for straight forward mapping:

new Zend_Controller_Router_Route(
    '/category/:category/:page',
    array(
        'module' => 'dynamic',
        'controller' => 'index',
        'action' => 'show-category',
        'category' => 'news',
        'page' => 1   
    )
)

Will match /category/, /category/news/, /category/othercategory or /category/news/4 (examples only of course).

Upvotes: 1

Related Questions