Created
January 8, 2014 11:37
-
-
Save csrui/8315569 to your computer and use it in GitHub Desktop.
Handle language changing in CakePHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
App::uses('Component', 'Controller'); | |
class LanguageComponent extends Component { | |
public function initialize(Controller $controller) { | |
$this->autoSelectLanguage($controller); | |
} | |
private function autoSelectLanguage(Controller $controller) { | |
if (isset($controller->request->query['lang'])) { | |
$controller->Session->write('Config.language', $controller->request->query['lang']); | |
} | |
if ($controller->Session->check('Config.language')) { | |
Configure::write('Config.language', $controller->Session->read('Config.language')); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment