0

我在 KNP Doctrine 行为中使用 A2lix 翻译形式。

这些字段在表单中正确显示并且它们也被正确发送(我已经在调试中检查过)但它们没有保存在数据库中。

这是我的代码:

表格类型

/**
     * Buildform function
     *
     * @param FormBuilderInterface $builder the formBuilder
     * @param array                $options the options for this form
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
            ->add('code', 'text', [
                'required' => true,
            ])
            ->add('translations', 'a2lix_translations');
    }

配件实体

<?php

namespace SocialCar\CoreBundle\Entity;

use Knp\DoctrineBehaviors\Model as ORMBehaviors;

class Accessory
{
    use ORMBehaviors\Translatable\Translatable;

    /**
     * @var integer
     */
    private $id;

    /**
     * @var string
     */
    private $code;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set code
     *
     * @param string $code
     * @return Accessory
     */
    public function setCode($code)
    {
        $this->code = $code;

        return $this;
    }

    /**
     * Get code
     *
     * @return string 
     */
    public function getCode()
    {
        return $this->code;
    }
}

附件翻译

<?php

namespace SocialCar\CoreBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;

/**
 * AccessoryTranslation
 */
class AccessoryTranslation
{
    use ORMBehaviors\Translatable\Translation;

    /**
     * @var string
     */
    private $name;


    /**
     * Set name
     *
     * @param string $name
     * @return AccessoryTranslation
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }
}

有任何想法吗?

4

2 回答 2

1

您是否在 config.yml 文件中激活了 knp 可翻译行为?

knp_doctrine_behaviors:
    blameable:      ~
    geocodable:     ~     
    loggable:       ~
    sluggable:      ~
    soft_deletable: ~
    translatable:   true
于 2017-04-19T13:37:02.067 回答
0

您需要定义实体和翻译实体之间的关系:

配饰:

/**
 * @ORM\OneToMany(targetEntity="AccessoryTranslation", mappedBy="accessory", cascade={"persist", "remove"})
 */
protected $translations;

附件翻译:

/**
 * @ORM\ManyToOne(targetEntity="Accessory", inversedBy="translations")
 * @ORM\JoinColumn(name="accessory_id", referencedColumnName="id", onDelete="CASCADE")
 */
protected $object;
于 2015-05-20T13:49:24.527 回答