Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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