Skip to content

Instantly share code, notes, and snippets.

@ezimuel
Created June 18, 2014 08:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezimuel/92d9f6b8ed62f9fd71c7 to your computer and use it in GitHub Desktop.
Save ezimuel/92d9f6b8ed62f9fd71c7 to your computer and use it in GitHub Desktop.
Optional language parameter in a ZF2 route
<?php
// route configuration, for instance in a module.config.php
// ...
'home' => array(
'type' => 'segment',
'options' => array(
'route' => '/[:lang/]',
'defaults' => array(
'__NAMESPACE__' => 'Application\Controller',
'controller' => 'Index',
'action' => 'index',
'lang' => 'en',
),
'constraints' => array(
'lang' => 'en|fr'
),
),
'may_terminate' => true,
'child_routes' => array(
'page-one' => array(
'type' => 'segment',
'options' => array(
'route' => 'page-one',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'page-one',
),
),
),
'page-two' => array(
'type' => 'segment',
'options' => array(
'route' => 'page-two',
'defaults' => array(
'controller' => 'Application\Controller\Index',
'action' => 'page-two',
),
),
),
),
),
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment