CakePHP multilingual route
If you're working on multilingual CakePHP app, you will need to create multilingual routes. Most common case is to have these urls:
www.example.com/en/demo
www.example.com/de/demo
So, our app will have first param (en, de & etc) for selecting language. Open /app/Config/routes.php and add:
Router::connect('/:i10n/:controller', array('action' => 'index'), array('i10n' => '[a-z]{2}'));
Router::connect('/:i10n/:controller/:action/*', array(), array('i10n' => '[a-z]{2}'));
Reg expression array('i10n' => '[a-z]{2}') defines that language code should be any two lowercase letters.
It's a very basic example, but will show you have route works.
Written by Mindaugas
Related protips
1 Response
You might even define only some languages to match:
Router::connect('/:i10n/:controller/:action/*', array(), array('i10n' => 'en|de|it|es'));
In this way you could use another 2char string to match another rule (ex: /up/files)
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#