2012-09-19 14 views
1

我有一個一對多的自引用實體。只要父值設置爲空,一切正常。當我的父項列表中的實際設置的東西,我得到的錯誤:Symfony2/Doctrine一對多:類整數不存在

Class integer does not exist

500 Internal Server Error - 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; 
    } 
} 

我在做什麼錯?

回答

2

你不能在PHP中的標量類型(整數/字符串/布爾等)上鍵入提示。例如

public function setSortOrder(\integer $sortOrder) 

應該是:

public function setSortOrder($sortOrder) 

您可以在方法中驗證的值的類型,也許如果傳遞的東西是不是整數拋出InvalidArgumentException。

+0

傑出!非常感謝。我沒有注意到它,因爲教義爲我創造了二傳手。 – rooter

相關問題