我已经按照此处的示例实施了翻译。
在我的实体中,我应该添加魔术方法__call
:
class Occupation
{
use ORMBehaviors\Translatable\Translatable;
/* ... attributes ... */
public function __call($method, $arguments)
{
return $this->proxyCurrentLocaleTranslation($method, $arguments);
}
}
但是,当获取以下形式的数据时,不会调用此方法:
class PostJobStep1Type extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('occupation', EntityType::class, [
'label' => 'form.occupation',
'class' => Occupation::class,
'choice_label' => 'name'
]);
}
}
所以我得到一个错误:
该属性
name
和方法之一getName()
,name()
,isName()
,都不存在并且在类hasName()
中__get()
具有公共访问权限AppBundle\Entity\Occupation
。
有什么办法也可以强制Symfony
检查魔术方法__call
吗?
非常感谢