如何更新翻译cakephp但不是主表 [英] How to update translation cakephp but not main table

查看:125
本文介绍了如何更新翻译cakephp但不是主表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为模型添加了翻译行为,模型来自这里

I have added translate behaviour to a model, the model comes here

App::uses('AppModel', 'Model');
class Category extends AppModel
{
    public $hasMany = "Product";
    public $validate = array(
        'name' => array(
            'rule' => 'notEmpty'
        )
    );
    public $actsAs = array(
        'Translate' => array(
            'name','folder','show'
        )
    );
    public $name = "Category";

    public $translateModel = 'KeyTranslate';
}

并控制更新模型的控制器

And heres the controller for updating the model

public function admin_edit_translate($id,$locale)
    {

    $this->Category->locale = $locale;          
    $category = $this->Category->findById($id);

    if ($this->request->is('post') || $this->request->is('put')) {
        $this->Category->id = $id;
        if ($this->Category->save($this->request->data)) {
            $this->Session->setFlash('Category translate has been updated');
            //$this->redirect(array('action' => 'edit',$id));
        } else {
            $this->Session->setFlash('Unable to update category');
        }
    }
    if (!$this->request->data) {
        $this->request->data = $category;
    }
    }   

我的问题是,类别数据库,当我更新或创建一个新的翻译,它会与翻译的值更新。如何避免

My Problem is that i have a name field in the categories database and when i update or create a new translation it gets updated with the translated value. How do i avoid that

推荐答案

回调 Behavior :: beforeSave Model :: beforeSave ...

但最简单的方法是修改在实际保存之前,<:: 之前<:: cc> c> c:

but, the simplest way to modify data in Model::beforeSave before Behavior::beforeSave before realy saving is:

$this->Behaviors->Behavior_Name->runtime[Model_Name]['beforeSave'][Field_Name] = '...';

这篇关于如何更新翻译cakephp但不是主表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆