我需要收到一个单独的翻译内容,以填写表格。
控制器中的
public function translate($id = null)
{
$this->Apartments->locale('deu');
$apartment = $this->Apartments->get($id);
.....
$this->set(compact('apartment'));
$this->set('_serialize', ['apartment']);
}我还没收到翻译的内容!
表中的
public function initialize(array $config)
{
parent::initialize($config);
$this->table('apartments');
$this->displayField('name');
$this->primaryKey('id');
$this->addBehavior('Timestamp');
$this->addBehavior('Translate', ['fields' => ['description']]);
}接收翻译后的内容的正确方法是什么?我需要在表类和实体类中添加什么才能使其工作?
更新 SQL查询
SELECT Apartments.id AS `Apartments__id`,
Apartments.user_id AS `Apartments__user_id`,
Apartments.name AS `Apartments__name`,
Apartments.slug AS `Apartments__slug`,
Apartments.description AS `Apartments__description`,
Apartments.number_of_rooms AS `Apartments__number_of_rooms`,
Apartments.number_of_beds AS `Apartments__number_of_beds`,
Apartments.badroom AS `Apartments__badroom`,
Apartments.surface AS `Apartments__surface`,
Apartments.internet AS `Apartments__internet`,
Apartments.air_condition AS `Apartments__air_condition`,
Apartments.parking AS `Apartments__parking`,
Apartments.pets AS `Apartments__pets`,
Apartments.created AS `Apartments__created`,
Apartments.modified AS `Apartments__modified`,
Apartments.active AS `Apartments__active`,
Apartments_description_translation.id AS `Apartments_description_translation__id`,
Apartments_description_translation.locale AS `Apartments_description_translation__locale`,
Apartments_description_translation.model AS `Apartments_description_translation__model`,
Apartments_description_translation.foreign_key AS `Apartments_description_translation__foreign_key`,
Apartments_description_translation.field AS `Apartments_description_translation__field`,
Apartments_description_translation.content AS `Apartments_description_translation__content`
FROM apartments Apartments
LEFT JOIN i18n Apartments_description_translation ON (Apartments_description_translation.model = 'Apartments'
AND Apartments_description_translation.field = 'description'
AND Apartments_description_translation.locale = 'deu'
AND Apartments.id = (Apartments_description_translation.foreign_key))
WHERE Apartments.id = 1 LIMIT 1发布于 2015-09-15 09:54:54
你在评论中提到:
我使用一个现有的数据库,其中包含基于CakePHP 2的应用程序输入的数据。..。在i18n表中,我有一个模型名公寓,但是cakephp3搜索公寓。
模型字段值是CakePHP 2(单数)中模型的名称,CakePHP 3中的表名(复数)。
要解决这个问题,您可以:
迁移翻译表中的数据
这是最符合逻辑的解决方案,除非仍然有CakePHP 2.x代码查看翻译记录,只需更新翻译记录:
UPDATE i18n set model = "Apartments" where model = "Apartment";
... etc ...更改所使用的引用
默认情况下,模型字段是表类的名称,但它不一定是可配置
public function initialize(array $config)
{
parent::initialize($config);
...
$this->addBehavior('Translate', [
'fields' => ['description'],
'referenceName' => 'Apartment' # <-
]);
}通过这种方式,CakePHP 3.x代码将与早期版本兼容。
https://stackoverflow.com/questions/32581772
复制相似问题