我有一对多的自引用实体。只要父值设置为null,一切正常。当我将父项设置为列表中的实际内容时,我收到错误:
类整数不存在
500内部服务器错误 - ReflectionException
以下是我的实体的代码:
<?php
namespace WorkRecorder\WorkBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @ORM\Entity(repositoryClass="WorkRecorder\WorkBundle\Repository\WorkRepository")
* @ORM\Table(name="strategyUsed")
*/
class StrategyUsed
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="integer")
*/
protected $sortOrder;
/**
* @ORM\Column(type="string", length=50)
*/
protected $name;
/**
* @ORM\Column(type="text")
*/
protected $description;
/**
* @ORM\OneToMany(targetEntity="StrategyUsed", mappedBy="parent")
*/
private $children;
/**
* @ORM\ManyToOne(targetEntity="StrategyUsed", inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
*/
private $parent;
public function __construct() {
$this->children = new \Doctrine\Common\Collections\ArrayCollection();
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* Get name
*
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Set description
*
* @param text $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* Get description
*
* @return text
*/
public function getDescription()
{
return $this->description;
}
/**
* Set sortOrder
*
* @param integer $sortOrder
*/
public function setSortOrder(\integer $sortOrder)
{
$this->sortOrder = $sortOrder;
}
/**
* Get sortOrder
*
* @return integer
*/
public function getSortOrder()
{
return $this->sortOrder;
}
/**
* Add children
*
* @param WorkRecorder\WorkBundle\Entity\StrategyUsed $children
*/
public function addStrategyUsed(\WorkRecorder\WorkBundle\Entity\StrategyUsed $children)
{
$this->children[] = $children;
}
/**
* Get children
*
* @return Doctrine\Common\Collections\Collection
*/
public function getChildren()
{
return $this->children;
}
/**
* Set parent
*
* @param WorkRecorder\WorkBundle\Entity\StrategyUsed $parent
*/
public function setParent(\WorkRecorder\WorkBundle\Entity\StrategyUsed $parent)
{
$this->parent = $parent;
}
/**
* Get parent
*
* @return WorkRecorder\WorkBundle\Entity\StrategyUsed
*/
public function getParent()
{
return $this->parent;
}
}
我做错了什么?
答案 0 :(得分:2)
您无法在PHP中键入标量类型(整数/字符串/布尔值等)的提示。 e.g。
public function setSortOrder(\integer $sortOrder)
应该是:
public function setSortOrder($sortOrder)
您可以验证方法中值的类型,如果传递了一个不是整数的东西,可能会抛出InvalidArgumentException。