Search code examples
zend-framework2zend-route

Zend framework 2 dynamic routing


I want to write routes for this type of urls

http://www.example.com/category/sub-category/id.html

here category is dynamic. means- i have 100 of categories in my db. sub category is also dynamic. i need to show page based on id value. Any one please suggest.


Solution

  • Try reading the docs first its very simple :

    'sample' => array(
                    'type' => 'Segment',
                    'options' => array(
                        'route' => '/:category[/:sub_category[/:id]].html',
                        'defaults' => array(
                            'controller' => 'Your Controller',
                            'action' => 'Your Action',
                        ),
                    ),
                ),
    

    With this router config you can have :

    http://www.example.com/category.html
    http://www.example.com/category/sub-category.html
    http://www.example.com/category/sub-category/id.html