core.php中
<?php
Configure::write('debug', 2);
Configure::write('Error', array(
'handler' => 'ErrorHandler::handleError',
'level' => E_ALL & ~E_DEPRECATED,
'trace' => true
));
Configure::write('Exception', array(
'handler' => 'ErrorHandler::handleException',
'renderer' => 'ExceptionRenderer',
'log' => true
));
Configure::write('App.encoding', 'UTF-8');
Configure::write('Session', array(
'defaults' => 'php'
));
Configure::write('Security.salt', '7f19b3be4ee7a22fa2e415279337475c4c7a97e8');
Configure::write('Security.cipherSeed', '474149355628227626166274362321');
Configure::write('Acl.classname', 'DbAcl');
Configure::write('Acl.database', 'default');
$engine = 'File';
$duration = '+999 days';
if (Configure::read('debug') > 0) {
$duration = '+10 seconds';
}
$prefix = 'myapp_';
Cache::config('_cake_core_', array(
'engine' => $engine,
'prefix' => $prefix . 'cake_core_',
'path' => CACHE . 'persistent' . DS,
'serialize' => ($engine === 'File'),
'duration' => $duration
));
Cache::config('_cake_model_', array(
'engine' => $engine,
'prefix' => $prefix . 'cake_model_',
'path' => CACHE . 'models' . DS,
'serialize' => ($engine === 'File'),
'duration' => $duration
));
?>
bootstrap.php中
<?php
Cache::config('default', array('engine' => 'File'));
CakePlugin::load('DebugKit');
Configure::write('Config.languages', array('jap', 'eng'));
Configure::write('Config.language', 'jap');
Configure::write('Dispatcher.filters', array(
'AssetDispatcher',
'CacheDispatcher'
));
App::uses('CakeLog', 'Log');
CakeLog::config('debug', array(
'engine' => 'File',
'types' => array('notice', 'info', 'debug'),
'file' => 'debug',
));
CakeLog::config('error', array(
'engine' => 'File',
'types' => array('warning', 'error', 'critical', 'alert', 'emergency'),
'file' => 'error',
));
?>
routes.php文件
Router::connect('/:language/:controller/:action/*', array(), array('language' => '[a-z]{3}'));
Router::connect('/:language/login', array('controller' => 'users', 'action' => 'login'), array('language' => '[a-z]{3}'));
Router::connect('/:language/logout', array('controller' => 'users', 'action' => 'logout'), array('language' => '[a-z]{3}'));
Router::connect('/:language/dashboard', array('controller' => 'users', 'action' => 'display'), array('language' => '[a-z]{3}'));
Router::connect('/:language/:controller/*', array(), array('language' => '[a-z]{3}'));
Router::connect('/:language/', array('controller' => 'pages', 'action' => 'display', 'home'), array('language' => '[a-z]{3}'));
appcontroller.php
<?php
App::uses('Controller', 'Controller');
class AppController extends Controller {
public $components = array(
'DebugKit.Toolbar',
'Session',
'Cookie',
'Auth' => array(
'loginRedirect' => array('controller' => 'users', 'action' => 'index'),
'logoutRedirect' => array('controller' => 'users', 'action' => 'login'),
'authError' => 'You must be logged in to view this page.',
'loginError' => 'Invalid Username or Password entered, please try again.',
));
public $helpers = array('Html' => array('className' => 'MyHtml'));
public function beforeFilter() {
$this->Auth->allow('login');
$this->_setLanguage();
}
private function _setLanguage() {
if ($this->Cookie->read('language') && !$this->Session->check('Config.language')) {
$this->Session->write('Config.language', $this->Cookie->read('language'));
} 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('language', $this->params['language'], false, '20 days');
}
}
public function redirect($url, $status = NULL, $exit = true) {
if (!isset($url['language']) && $this->Session->check('Config.language')) {
$url['language'] = $this->Session->read('Config.language');
}
parent::redirect($url, $status, $exit);
}
}
?>
我想为我的应用程序使用多种语言。没关系,但我想点击链接
echo $this->Html->link("Home", array('controller'=>'pages','action'=>'index'));
像那样。应用程序在我的链接中自动添加语言,例如http://mydomain/TestInternationalChange/jap/posts/index
不是http://mydomain/TestInternationalChange/posts/index
。我的apphelper.php和myhtmlhelper.php为空。