Tuesday, December 25, 2012

Zend framework 2 route example


router' => array(
    'routes' => array(
      'bannermgt' => array(
        'type' => 'segment',
        'options' => array(
          'route' => '/bannermgt[/:action][/:id][/page/:page][/searchname/:searchname][/searchpath:searchpath][/]',
          'constraints' => array(
            'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
            'id' => '[0-9]+',
            'page' => '[0-9]+',
            'searchname' => '[^/]*',
            'searchpath' => '[^/]*',
          ),
          'defaults' => array(
            'controller' => 'BannerMgt',
            'action' => 'index',
            "page" => 1,
            "searchname" => "",
            "searchpath" => ""
          ),
        ),
      ),
    ),
  ),

Take note that ordering of URL in route is strict.
Therefore searchname must come first before searchpath.

Or else , you may ommit:
[/searchname/:searchname][/searchpath:searchpath]
And append as querystring
/bannermgt/list?searchpath=xxx&searchname=yyy

No comments: