0

它可以在一个表单中保存同一字段的多个翻译吗?我有一个带有行为翻译的模型来翻译名称字段。三个翻译(deu、eng、ita)已正确记录在 i18n 表中,但该字段未正确验证!有什么建议么?

应用程序/模型/Category.php

class Category extends AppModel {
    public $actsAs = array('Translate' => array('name' => 'TranslateName'));
    public $validate = array(
        'name' => array(
            'notempty' => array(
                'rule' => array('notempty'),
                'message' => 'Error notempty',
            ),
        ),
    );
    ...

应用程序/查看/类别/admin_edit.ctp

<?php
echo $this->Form->create('Category');
echo $this->Form->input('Category.id');
echo $this->Form->input('Category.name.deu', array('label' => __d('Category', 'Name Deu')));
echo $this->Form->input('Category.name.eng', array('label' => __d('Category', 'Name Eng')));
echo $this->Form->input('Category.name.ita', array('label' => __d('Category', 'Name Ita')));
echo $this->Form->end(__d('app', 'Submit'));
?>

应用程序/视图/控制器/CategoriesController.php

if ($this->Category->save($this->request->data)) {
    $this->Session->setFlash(__d('Category', 'The category has been saved'));
} else {
    $this->Session->setFlash(__d('Category', 'The category could not be saved. Please, try again.'));
}
4

1 回答 1

2

我有一个类似的问题

但是你可以试试这个 - 它应该为你解决它:https ://github.com/zoghal/cakephp-MultiTranslateBehavior

于 2012-05-15T13:54:07.037 回答