Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class AppController extends Controller {
- var $components = array ('Cookie','Session','Geoip');
- var $dbconfigs = array ('deu' => array(
- 'driver' => 'mysql',
- 'persistent' => false,
- 'host' => 'localhost',
- 'login' => 'root',
- 'password' => '',
- 'database' => 'countitdown_deu'),
- 'eng' => array(
- 'driver' => 'mysql',
- 'persistent' => false,
- 'host' => 'localhost',
- 'login' => 'root',
- 'password' => '',
- 'database' => 'countitdown_eng')
- );
- function beforeFilter() {
- $this->_setLanguage();
- }
- function _setLanguage() {
- $ip = $this->Geoip->findIp();
- if (isset($ip)) {
- $geo = $this->Geoip->lookupIp($ip);
- }
- if ($this->Cookie->read('lang') && !$this->Session->check('Config.language')) {
- $this->Session->write('Config.language', $this->Cookie->read('lang'));
- }
- else if (isset($this->params['language']) && ($this->params['language']
- != $this->Session->read('Config.language'))) {
- $this->Session->write('Config.language', $this->params['language']);
- $this->Cookie->write('lang', $this->params['language'], false, '40 days');
- }
- else if (isset($geo) && ($geo != "") && (!$this->Cookie->read('lang') && !$this->Session->check('Config.language'))){
- $this->Session->write('Config.language', $geo['country_code3']);
- $this->Cookie->write('lang', $geo['country_code3'], false, '40 days');
- }
- Configure::write('Config.language',$this->Session->read('Config.language'));
- if ($this->Session->read('Config.language') == 'deu') {
- $db = ConnectionManager::getDataSource('default');
- $db->disconnect();
- $db->setConfig($this->dbconfigs['deu']);
- $db->connect();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement