Prestashop模型不会从lang表加载数据

时间:2019-04-28 11:40:06

标签: model prestashop lang

我正在prestashop模块中创建一个简单的模型,但无法使其从表lang中加载数据。

class Type extends ObjectModel
{
    /** @var int */
    public $id_type;

    /** @var varchar */
    public $titre;

    /** @var text */
    public $content;

    /** @var varchar */
    public $tags;

    public static $definition = array(
        'table' => 'type',
        'primary' => 'id_type',
        'fields' => array(
            'titre' =>              array('type' => self::TYPE_STRING, 'required' => true, 'lang' => true),
            'content' =>                array('type' => self::TYPE_STRING, 'required' => true, 'lang' => true),
            'tags' =>               array('type' => self::TYPE_STRING, 'required' => true),
        ),
    );
}
database : 
ps_type [id_type, id_shop_group, id_shop, tags]
ps_type_lang [id_type, id_lang, titre, content]

当我从数据库中加载新的Type(1)之类的行时;我有标签字段,但没有标题和内容。 我错过了什么吗?

1 个答案:

答案 0 :(得分:1)

您必须添加“ multilang”

    public static $definition = array(
        'table' => 'type',
        'primary' => 'id_type',
        'multilang' => true,
        'fields' => array(
            'titre' =>     array('type' => self::TYPE_STRING, 'required' => true, 'lang' => true),
            'content' =>   array('type' => self::TYPE_STRING, 'required' => true, 'lang' => true),
            'tags' =>      array('type' => self::TYPE_STRING, 'required' => true),
        ),
    );


$type = new Type(1, 2); // 2 is your language id