2016-03-05 62 views
1

对不起,我希望你能理解我。 简化的代码看起来是这样的:CakePHP 3不支持默认语言

//在bootstrap.php中

的ini_set( 'intl.default_locale', '申');

// MainMenusTable.php

公共函数初始化(数组$配置) { 父::初始化($配置); ...

$this->addBehavior('Translate', ['fields' => ['title']]); 

... }

//在控制器 - 这个作品!

public function add() 
{ 

    I18n::locale('eng'); 
    $mainMenu = $this->MainMenus->newEntity(); 
    if ($this->request->is('post')) {  
     $mainMenu = $this->MainMenus->patchEntity($mainMenu, $this->request->data); 
     $this->MainMenus->save($mainMenu) 
    } 
    $this->set(compact('mainMenu')); 
} 

//在控制器,但本开不工作:

public function add() 
{ 

    I18n::locale('deu'); 
    $mainMenu = $this->MainMenus->newEntity(); 
    if ($this->request->is('post')) {  
     $mainMenu = $this->MainMenus->patchEntity($mainMenu, $this->request->data); 
     $this->MainMenus->save($mainMenu) 
    } 
    $this->set(compact('mainMenu')); 
} 

我有同样的问题,当我读到记录

//在控制器 - 这工作!

I18n::locale('eng');  
    $query = $this->MainMenus->find('all')->order(['MainMenus.id' => 'ASC'])->all(); 

//在控制器,但本开不工作:

I18n::locale('deu');  
    $query = $this->MainMenus->find('all')->order(['MainMenus.id' => 'ASC'])->all(); 

对于 '申' 我手动输入记录。 你知道问题是什么吗? 谢谢!

回答

1

这是对该问题的解决方案(来自另一个论坛): 此行为假定您以默认语言存储记录。如果当前语言环境与默认语言相同,则它只会返回数据库中的记录,而不是从翻译表中获取。 标题将不会保存在i18n表中默认的语言中,仅针对其他语言。