Reputation: 157
I need to build a multi-lingual site with the language in the url like this http://example.org/jp/users/login, but I want to avoid having to code the language into every link on the site. I effectively have this for routing:
$routes->connect(
'/:lang/:controller/:action/*',
['prefix' => 'customer'],
['routeClass' => 'DashedRoute', 'lang' => '[a-z]{2}']
);
And I have to do this for links:
$this->Html->link(__('List Users'), ['lang' => 'en', 'controller' => 'users', 'action' => 'index']);
Is there any way so that lang can be added automatically and I can just do this for links instead?
$this->Html->link(__('List Users'), ['controller' => 'users', 'action' => 'index']);
Upvotes: 0
Views: 519
Reputation: 8100
Just add 'persist' => ['lang']
to options array of your $routes->connect()
statement.
Upvotes: 3