我正在使用knplabs/doctrine-behaviors
捆绑包翻译某些Entity字段。这对我的大多数情况都很好,并且a2lix/translation-form-bundle
捆绑包非常适合用来生成表格。我刚遇到一个特定的问题,我希望其他人可以解决:我需要从扩展了抽象类的类中转换字段。
所以我有Step抽象类:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
/**
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorMap( {"stephardware" = "StepHardware","stepquestion" = "StepQuestion"} )
*/
abstract class Step
{
use ORMBehaviors\Translatable\Translatable;
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
protected $id;
// getters and setters
}
哪个由StepHardware类扩展:
<?php
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\StepHardwareRepository")
*/
class StepHardware extends Step
{
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Product",inversedBy="stepHardwares")
*/
private $Products;
/**
* @ORM\Column(type="boolean")
*/
private $Optional;
/**
* @ORM\OneToOne(targetEntity="App\Entity\Step",cascade={"persist","remove"})
*/
private $NextStep;
/**
* @ORM\Column(type="boolean",nullable=true)
*/
private $Multichoice;
// Getters and setters
}
并由另一个抽象类翻译:
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
/**
* @ORM\Entity
* @ORM\InheritanceType("JOINED")
* @ORM\DiscriminatorMap( {"stephardware" = "StepHardware","stepquestion" = "StepQuestion"} )
*/
abstract class StepTranslation
{
use ORMBehaviors\Translatable\Translation;
/**
* @ORM\Column(type="text")
*/
protected $Question;
// getters and setters
}
问题是,当我提交表单时,我收到一条消息,提示我正在尝试实例化一个抽象类...我该如何翻译基于抽象类的类?
我可以在StepHardware类中设置Question属性,但这并不是干净的编码,因为我还有其他基于Step抽象类的类。