2016-03-05 58 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表中默認的語言中,僅針對其他語言。