Symfony2和学说希望" drifes"相反"驱动"

时间:2014-07-30 07:30:30

标签: php symfony doctrine-orm doctrine-odm

提交表单时出现此错误。

Exception: Neither the property "drives" nor one of the methods "addDrife()", "setDrives()", "__set()" or "__call()" exist and have public access in class "Acme\DemoBundle\Entity\User".

但实体中的一切都是正确的。 我在映射中没有错误,一切都是有效的。

如果我搜索" drife" IntelliJ IDEA说:没有匹配

实体:

/**
 * @var Drive[]
 *
 * @ORM\OneToMany(targetEntity="Drive", mappedBy="user", cascade={"all"}, orphanRemoval=true, fetch="EXTRA_LAZY")
 */
private $drives;

public function __construct()
{
    parent::__construct();
    $this->drives = new \Doctrine\Common\Collections\ArrayCollection();
}

public function addDrive(Drive $drive)
{
    $drive->setUser($this);
    $this->drives[] = $drive;

    return $this;
}

public function removeDrive(Drive $drive)
{
    $drive->setUser();
    $this->drives->removeElement($drive);
}

public function getDrives()
{
    return $this->drives;
}

1 个答案:

答案 0 :(得分:0)

通过添加此解决方案。

我应该阅读更多......

/**
 * Set drives
 *
 * @param Drive[] $drives
 * @return User $this
 */
public function setDrives($drives)
{
    foreach($this->drives as $drive)
    {
        $this->removeDrive($drive);
    }
    foreach($drives as $drive)
    {
        $this->addDrive($drive);
    }
    return $this;
}

或者将其重命名为" HardDrives"。

问题是StringUtil。

/vendor\symfony\symfony\src\Symfony\Component\PropertyAccess\StringUtil.php:85

// hooves (hoof), dwarves (dwarf), elves (elf), leaves (leaf), caves (cave), staves (staff)
array('sev', 3, true, true, array('f', 've', 'ff')),

so dri - > ves< - 将是dri - > fes< - 。