[英]Symfony2 - Problems with mapping object in field form
Objective
has one Perspective
Objective
有一个Perspective
class Objective{
...
public function setPerspective(\Cboujon\BSCBundle\Entity\Pespective $perspective = null)
{
$this->perspective = $perspective;
return $this;
}
}
Objective.orm.yml Objective.orm.yml
Cboujon\BSCBundle\Entity\Objective:
manyToOne:
perspective:
targetEntity: Perspective
inversedBy: objectives
joinColumn:
name: perspective_id
referencesColumn: id
ObjectiveType.php ObjectiveType.php
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('perspective');
}
Symfony2 renders a form with combobox with all perspectives. Symfony2使用带有所有透视图的组合框来呈现表单。 That is ok!
那没问题! butn when I submit the
create form
I get the error: 但是,当我提交
create form
,出现错误:
ContextErrorException: Catchable Fatal Error: Argument 1 passed to Cboujon\\BSCBundle\\Entity\\Objective::setPerspective() must be an instance of Cboujon\\BSCBundle\\Entity\\Pespective, instance of Cboujon\\BSCBundle\\Entity\\Perspective given, called in /home/cristhian/php_apps/Symfony/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php on line 376 and defined in /home/cristhian/php_apps/Symfony/src/Cboujon/BSCBundle/Entity/Objective.php line 63
ContextErrorException:可捕获的致命错误:传递给Cboujon \\ BSCBundle \\ Entity \\ Objective :: setPerspective()的参数1必须是Cboujon \\ BSCBundle \\ Entity \\ Pespective的实例,是Cboujon \\ BSCBundle \\ Entity \\ Perspective的实例,在/ home中调用第376行的/cristhian/php_apps/Symfony/vendor/symfony/symfony/src/Symfony/Component/PropertyAccess/PropertyAccessor.php,并在/home/cristhian/php_apps/Symfony/src/Cboujon/BSCBundle/Entity/Objective.php中定义63行
Note: I also try: 注意:我也尝试:
$builder->add('perspective', 'entity', array(
'class' => 'CboujonBSCBundle:Perspective',
)
)
;
But I get the same error. 但是我得到了同样的错误。
Note2: If I remove \\Cboujon\\BSCBundle\\Entity\\Pespective
from setPerspective definition I can submit the form OK. 注意2:如果我从setPerspective定义中删除
\\Cboujon\\BSCBundle\\Entity\\Pespective
Pespective,则可以提交OK表单。
What am I doing wrong? 我究竟做错了什么?
iThere is a typo in your Entity setter when specifying the argument type: 指定参数类型时,实体设置器中有一个错字:
public function setPerspective(\Cboujon\BSCBundle\Entity\Pespective $perspective = null)
{
$this->perspective = $perspective;
return $this;
}
Not \\Cboujon\\BSCBundle\\Entity\\ Pespective , but \\Cboujon\\BSCBundle\\Entity\\ Perspective 不是\\ Cboujon \\ BSCBundle \\实体\\ 阈看 ,但\\ Cboujon \\ BSCBundle \\实体\\ 视角
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.