Php Symfony-导致错误“;类型为“的预期参数”;用框架奏鸣曲
此处函数覆盖名为Sonata的基于框架,Sonata正在构建管理模板:Php Symfony-导致错误“;类型为“的预期参数”;用框架奏鸣曲,php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,此处函数覆盖名为Sonata的基于框架,Sonata正在构建管理模板: protected function configureFormFields(FormMapper $formMapper){ $formMapper->add('owner', 'sonata_type_model_list', array( 'class' => 'XYZXBundle:ContestUser', 'btn_add' => false,
protected function configureFormFields(FormMapper $formMapper){
$formMapper->add('owner', 'sonata_type_model_list',
array(
'class' => 'XYZXBundle:ContestUser',
'btn_add' => false, //Specify a custom label
'btn_list' => 'Search', //which will be translated
'btn_delete' => false, //or hide the button.
'btn_catalogue' => 'SonataNewsBundle', //Custom translation domain for buttons
), array(
'placeholder' => 'No owner selected'
))
}
对象结构:
/**
* @ORM\ManyToOne(targetEntity="XYZ\XBundle\Entity\ContestUser")
* @ORM\JoinColumn(name="owner_id", referencedColumnName="id")
* @var XYZ\XBundle\Entity\ContestUser
*/
protected $owner;
当我尝试插入新行时发生
堆栈跟踪错误:
类型的预期参数
“XYZ\XBundle\Entity\XYZ\XBundle\Entity\user”,
中给出的“XYZ\XBundle\Entity\contestituser”
供应商\symfony\symfony\src\symfony\Component\PropertyAccess\PropertyAccessor.php
第254行
更新1
我试图像下面那样使用,但仍然导致相同的错误
* @ORM\ManyToOne(targetEntity="\XYZ\XBundle\Entity\ContestUser")
or
* @ORM\ManyToOne(targetEntity="ContestUser")
更新2
文件XYZ\X\Entity\Contest.php
<?php
namespace XYZ\XBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Filesystem\Filesystem;
/**
* XYZ\XBundle\Entity\Contest
*
* @ORM\Table(name="contests")
* @ORM\Entity(repositoryClass="XYZ\XBundle\Entity\ListRepository")
* @ORM\HasLifecycleCallbacks()
*/
class Contest
第行的映射注释中有不正确的命名空间:
* @ORM\ManyToOne(targetEntity="XYZ\XBundle\Entity\ContestUser")
它表示相对于当前名称空间的名称空间
您应该在开头添加反斜杠,使其成为绝对名称空间
* @ORM\ManyToOne(targetEntity="\XYZ\XBundle\Entity\ContestUser")
或者仅使用类名,因为当前和contestituser
类似乎位于同一命名空间中:
* @ORM\ManyToOne(targetEntity="ContestUser")
第行的映射批注中有不正确的命名空间:
* @ORM\ManyToOne(targetEntity="XYZ\XBundle\Entity\ContestUser")
它表示相对于当前名称空间的名称空间
您应该在开头添加反斜杠,使其成为绝对名称空间
* @ORM\ManyToOne(targetEntity="\XYZ\XBundle\Entity\ContestUser")
或者仅使用类名,因为当前和contestituser
类似乎位于同一命名空间中:
* @ORM\ManyToOne(targetEntity="ContestUser")
我发现我的失败很愚蠢,我有:
public function setOwner(XYZ\XBundle\Entity\ContestUser $owner){}
该代码适用于我:
public function setOwner(\XYZ\XBundle\Entity\ContestUser $owner){}
我发现我的失败很愚蠢,我有:
public function setOwner(XYZ\XBundle\Entity\ContestUser $owner){}
该代码适用于我:
public function setOwner(\XYZ\XBundle\Entity\ContestUser $owner){}
targetEntity=“contestituser”
@malcolm,这不起作用targetEntity=“contestituser”
@malcolm,这不起作用,这意味着你在其他地方也有这个问题。查找此类的所有用法并检查名称空间是否正确。这意味着您在其他地方也存在该问题。查找此类的所有用法并检查命名空间是否正确。