ok, after some hacking with routes I've found a solution that
(fingers-crossed) works, everything seems fine at the moment. I hope this
helps somebody:

> Ben,
>thank you for the quick reply and the work around. Works good !
>
>Laurent.
>
>For the record here is the code: 
>$router = new Zend_Controller_Router_Rewrite();
>      
>    $languageRoute  = new Zend_Controller_Router_Route(':language',
>array('language' => 'fr'), array('language' => 'fr|en'));
>  
>    $route = new Zend_Controller_Router_Route_Static('',
>        array( 'module'     => 'default',
>               'controller' => 'index',
>               'action'     => 'index')
>    );
>    $router->addRoute('empty', $route);
>   
>    $route = new Zend_Controller_Router_Route(':language',
>        array( 'module'     => 'default',
>               'controller' => 'index',
>               'action'     => 'index'
>        )
>    );
>    $router->addRoute('language', $route);
>   
>    $defaultRoute = new
>Zend_Controller_Router_Route(':module/:controller/:action/*',
>        array( 'module'     => 'default',
>               'controller' => 'index',
>               'action'     => 'index'
>        )
>    );
>   
>    $router->addRoute('default', $languageRoute->chain($defaultRoute));

The above will work (thanks Laurent, Ben), though I had a few issues mainly
with using the url helper and Zend_Navigation e.g. 

echo $this->url(array(
    'controller'    => 'archive',
    'action'        => 'index',
), 'default', true);

the above will output  "/fr/default/archive"

we don't the "default" added to the url.

The other issue( though I think it's expected behaviour) I expected the
language param to populate itself e.g. if you have a url "/en" and you
navigate to it I expected the url created above to output
"/en/default/archive" but it doesn't, you have to set a global language
param say in a plugin preDispatch with something like:

$router->setGlobalParam('language', $locale->getLanguage());


with that now the url above will ouput what we expect "/en/default/archive".


In order to rid the "default" from the urls ( and there a few other quirks
we want to address too) I found that using the
"Zend_Controller_Router_Route_Module" route as your default chained to the
language route will do the trick (I still don't understand chained routes
the documentation on it isn't the best).

We also have to create an empty route so the homepage works e.g "domain.tld"
& "/". 

So our route is:

$emptyRoute = new Zend_Controller_Router_Route_Static('', array(
    'module'     => 'default',
    'controller' => 'index',
    'action'     => 'index'
));
$router->addRoute('empty', $emptyRoute);

$languageRoute = new Zend_Controller_Router_Route(
    ':language',
    array(
        'language' => 'fr',
        'module'     => 'default',
        'controller' => 'index',
        'action'     => 'index'
    ),
    array(
        'language' => 'en|fr'
    )
);
$router->addRoute('language', $languageRoute);

$defaultRoute = new Zend_Controller_Router_Route_Module(array(),
    $front->getDispatcher(), $front->getRequest()
);
$router->addRoute('default', $languageRoute->chain($defaultRoute));


The above is works, it's hacky and I don't like it in the least, but it
works. 


Hope that helps somebody.


Gerry


-- 
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/ZF-1-10-4-Chain-route-language-code-tp2282659p2308034.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to