cakephp3.0.0-rc2i18n::locale()不';t工作

cakephp3.0.0-rc2i18n::locale()不';t工作,php,cakephp,internationalization,locale,cakephp-3.0,Php,Cakephp,Internationalization,Locale,Cakephp 3.0,我使用的是CakePHP3.0.0-RC2。 工作正常,但我不能在登录时更改用户的du语言 我的登录功能不起作用。它什么也不做: public function login() { if ($this->request->is('post')) { $user = $this->Auth->identify(); if ($user) { $this->Auth->setUser($user);

我使用的是CakePHP3.0.0-RC2。 工作正常,但我不能在登录时更改用户的du语言

我的登录功能不起作用。它什么也不做:

public function login()
{
    if ($this->request->is('post')) {
        $user = $this->Auth->identify();
        if ($user) {
            $this->Auth->setUser($user);

            I18n::locale($user['lang']);

            return $this->redirect($this->Auth->redirectUrl());
        }

        $this->Flash->error(__("Nom d'utilisateur ou mot de passe incorrect, essayez à nouveau."));
    }
}
请注意,当我在引导中更改语言时,即ini_set('intl.default_locale','fr_fr');它工作正常,但我想在用户登录时更改语言。 我的桌面在Windows8.1上运行带有PHP5.5.2的Wampserver 我独立于Cakephp检查gettext函数。Il可以工作,但只有在下载后才能工作

你能帮我吗?
Christian

因为您重定向到另一个控制器。这意味着可以在该控制器或AppController中重写区域设置。你为什么不使用会话呢

    public function login()
{
    if ($this->request->is('post')) {
        $user = $this->Auth->identify();
        if ($user) {
            $this->Auth->setUser($user);

             $this->request->session()->write('Config.language', 'du');

            return $this->redirect($this->Auth->redirectUrl());
        }

        $this->Flash->error(__("Nom d'utilisateur ou mot de passe incorrect, essayez à nouveau."));
    }
}
以及在您的AppController(FrontController)中

class AppController extends Controller
{


    public function initialize()
    {

        $this->loadComponent('Flash');
        $this->layout = 'mysite';
        $lang=$this->request->session()->read('Config.language');
        switch($lang)
        {
            case "du":
                I18n::locale('du_DU');
                break;
            case "en":
                I18n::locale('en_EN');
                break;
            case "jp":
                I18n::locale('ja_JP');
                break;
            default:
                I18n::locale('en_EN');
                break;
        }