Skip to content

Instantly share code, notes, and snippets.

@ijmorgado
Last active December 11, 2015 21:58
Show Gist options
  • Save ijmorgado/4666293 to your computer and use it in GitHub Desktop.
Save ijmorgado/4666293 to your computer and use it in GitHub Desktop.
This is a snippet of route in ZF2 to handle url's like /controller/action, /controller/action/param1/value1, /controller/action/param1/value1/param2/value2...perhaps that's not the best way to do that but comming soon I would like to handle url's with undefined number of params with just one routing rule....
<?php
// ...the other options before.....
'home' => array(
'type' => 'Zend\Mvc\Router\Http\Literal',
'options' => array(
'route' => '/',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'index',
),
),
'may_terminate' => true,
'child_routes' => array(
'default' => array(
'type' => 'Segment',
'options' => array(
'route' => '[:controller[/:action[/:key/:value[/:key/:value]]]]',
'constraints' => array(
'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'key' => '[a-zA-Z][a-zA-Z0-9_-]+',
'value' => '[a-zA-Z]*[a-zA-Z0-9_-]*[0-9]*',
),
'defaults' => array(
),
),
),
'query' => array( 'type' => 'Query',
),
),
),
// // ...maybe the other options after.....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment