问题描述
我在实现 Gedmo\Translatable\Translatable
的学说中有类继承,
如果我自己获取数据,或者使用其他第三方库(如 EasyAdmin),它会根据 Accept-Language 标头正常工作。但是使用 api 平台我总是得到默认的。 对于没有类继承的任何其他实体,如果它有效。
这个例子在子类中实现了 Translatable,但我也在父类中尝试过。
我的配置是:
# config/packages/stof_doctrine_extensions.yaml
stof_doctrine_extensions:
default_locale: '%locale%'
translation_fallback: true
persist_default_translation: true
orm:
default:
timestampable: true
sluggable: true
blameable: true
translatable: true
<?PHP
namespace App\Entity;
use App\Repository\GreetingRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=GreetingRepository::class)
* @ORM\InheritanceType("JOINED")
* @ORM\discriminatorColumn(name="type",type="integer")
* @ORM\discriminatorMap({
* 0 = "App\Entity\Greeting",* 1 = "App\Entity\Hello",* })
*/
class Greeting
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
protected $id;
/**
* @ORM\Column(type="string",length=255)
* @Gedmo\Translatable
*/
protected $title;
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): self
{
$this->title = $title;
return $this;
}
}
<?PHP
namespace App\Entity;
use App\Repository\HelloRepository;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Translatable\Translatable;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=HelloRepository::class)
*/
class Hello extends Greeting implements Translatable
{
/**
* @ORM\Column(type="string",length=255)
* @Gedmo\Translatable
*/
protected $form;
public function getId(): ?int
{
return $this->id;
}
public function getForm(): ?string
{
return $this->form;
}
public function setForm(string $form): self
{
$this->form = $form;
return $this;
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)