0
votes

Hello I have two questions.

First I want to have a two languages in my website, and when the user clicks to the flag to change the language. The problem is that i don't want to use the languages files with extension .po in order to implement it because all the data are written in database. Without the framework of CakePHP i would pass a GET variable for e.g. ?lang=en and i could be able to read the proper records. If i use the same logic in CakePHP then i need to include this variable in all function inside the controllers my links will be something like /product/en/2. (but what happened in default language i must included there too...) So my main question is if i can handle this using another solution like SESSION for example, but then how can i change the SESSION variable when the user click another language ???

Similar problem i do have with my main menu, i want to include my menu in header (its also dynamic) in default.ctp file, how can i achieve this ? which is the main controller for the default file ? ? ? (on order to implement the function to read the values form the database).

Sorry for the big message and my english but i am new in CakePHP and general in MVC logic so i am a little bit confused from the way where i used to write in plain PHP.

Thanks!

1

1 Answers

0
votes

Use cakes named params for the language setting and the router to rewrite /lang:eng to /eng/.

You can check, set and alter this setting, and also the session, in AppController::beforeFilter(). This is your main controller from which all other controllers inherit from.

Reading the pretty well done official documentation is usually very helpful: See http://book.cakephp.org/2.0/en/core-libraries/internationalization-and-localization.html#localization-in-cakephp it describes exactly what I've written here.