This is how i understand / solved it:

>From what i understand, the ZF2's FrontController is more or less the
onBootstrap method in your module's Module class. (not sure if that
understanding is correct though)
My first approach was to find a way to read and reset the pathinfo i was
used to from ZF1, but after reading the  Routing
<http://framework.zend.com/manual/2.1/en/modules/zend.mvc.routing.html>  
part in the manual more thoroughly i realised i could also manage to do it
with just configuration.

This is how i set it up in module.config.php

return array(
    'controllers' => array(
        'invokables' => array(
            'MyWebsite\Controller\Home' =>
'MyWebsite\Controller\HomeController',
            'MyWebsite\Controller\Product' =>
'MyWebsite\Controller\ProductController',
            // [...]
        ),
    ),

    'router' => array(
        'routes' => array(
            'index' => array(
                'type'    => 'segment',
                'options' => array(
                    'route'    => '/',
                    'defaults' => array(
                        // this controller will detect there is no language
and then redirect to /[default_language]
                        'controller' => 'MyWebsite\Controller\Home',
                        'action'     => 'index',
                    ),
                ),
            ),
            'index_locale' => array(
                'type'    => 'segment',
                'options' => array(
                    'route'    => '/[:lang]',
                    'defaults' => array(
                        // same controller and action, but now the language
is set
                        // from here on we're gonna create children that
will all have the language set
                        'controller' => 'MyWebsite\Controller\Home',
                        'action'     => 'index',
                    ),
                    'constraints' => array(
                        'lang' => '[a-zA-Z]{2}'
                    ),
                ),
                'may_terminate' => true,
                'child_routes' => array(
                    // every child will have the language-part in the url
                    // so, /products[/:name], really is
/[:lang]/products[/:name]
                    'product' => array(
                        'type'    => 'segment',
                        'options' => array(
                            'route'    => '/products[/:name]',
                            'defaults' => array(
                                'controller' =>
'MyWebsite\Controller\Product',
                                'action'     => 'view',
                            ),
                        ),
                    ),
                    'products' => array(
                        'type'    => 'segment',
                        'options' => array(
                            'route'    => '/products',
                            'defaults' => array(
                                'controller' =>
'MyWebsite\Controller\Product',
                                'action'     => 'list',
                            ),
                        ),
                    ),
                    // etc.
?>

I hope this helps anyone else facing the same problem



--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/zf2-How-to-create-a-website-with-a-multilingual-part-tp4659349p4659378.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to