2013-07-26 51 views
4

我在將文件上傳到服務器時遇到此問題。錯誤:類...沒有字段或關聯名爲

Error: Class Prizes\PrizesBundle\Entity\Category has no field or association named order_cat 

我的類別分類:

<?php 

namespace Prizes\PrizesBundle\Entity; 
use Doctrine\ORM\Mapping as ORM; 
use Gedmo\Mapping\Annotation as Gedmo; 

/** 
* @ORM\Entity 
* @ORM\Table(name="category") 
*/ 
class Category 
{ 
    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    private $id; 

    /** 
    * @Gedmo\Translatable 
    * @ORM\Column(type="string", length=45, nullable=false) 
    */ 
    private $name; 

    /** 
    * @Gedmo\Translatable 
    * @ORM\Column(type="string", length=45, nullable=false) 
    */ 
    private $description; 

    /** 
    * @ORM\Column(type="string", length=255, nullable=false) 
    */ 
    private $thumb; 

    /** 
    * @ORM\Column(type="string", length=255, nullable=false) 
    */ 
    private $img; 

    /** 
    * @ORM\ManyToOne(targetEntity="Optime\AppStatusBundle\Entity\Status") 
    * @ORM\JoinColumn(name="status", referencedColumnName="id") 
    */ 
    private $status; 

    /** 
    * @Gedmo\Timestampable(on="create") 
    * @ORM\Column(type="datetime") 
    */ 
    private $created; 

    /** 
    * @Gedmo\Timestampable(on="update") 
    * @ORM\Column(type="datetime") 
    */ 
    private $modified; 

    /** 
    * @ORM\ManyToMany(targetEntity="Prize") 
    * @ORM\JoinTable(name="prize_has_category", 
    *  joinColumns={@ORM\JoinColumn(name="category", referencedColumnName="id")}, 
    *  inverseJoinColumns={@ORM\JoinColumn(name="prize", referencedColumnName="id")} 
    *  ) 
    */ 
    private $prizes; 

    /** 
    * @Gedmo\Locale 
    * Used locale to override Translation listener`s locale 
    * this is not a mapped field of entity metadata, just a simple property 
    */ 
    private $locale; 
    /** 
    * @Gedmo\Translatable 
    * @ORM\Column(type="string", length=45, nullable=false) 
    */ 
    private $order_cat; 
    // /** 
    //  * @Gedmo\TreeLeft 
    //  * @ORM\Column(name="lft", type="integer") 
    //  */ 
    // private $lft; 

    // /** 
    //  * @Gedmo\TreeLevel 
    //  * @ORM\Column(name="lvl", type="integer") 
    //  */ 
    // private $lvl; 

    // /** 
    //  * @Gedmo\TreeRight 
    //  * @ORM\Column(name="rgt", type="integer") 
    //  */ 
    // private $rgt; 

    // /** 
    //  * @Gedmo\TreeRoot 
    //  * @ORM\Column(name="root", type="integer", nullable=true) 
    //  */ 
    // private $root; 

    // /** 
    //  * @Gedmo\TreeParent 
    //  * @ORM\ManyToOne(targetEntity="Category", inversedBy="children") 
    //  * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="SET NULL") 
    //  */ 
    // private $parent; 

    // /** 
    //  * @ORM\OneToMany(targetEntity="Category", mappedBy="parent") 
    //  * @ORM\OrderBy({"lft" = "ASC"}) 
    //  */ 
    // private $children; 

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

    public function getId() 
    { 
    return $this->id; 
    } 

    public function setName($name) 
    { 
    $this->name = $name; 
    } 

    public function getName() 
    { 
    return $this->name; 
    } 

    public function setDescription($description) 
    { 
    $this->description = $description; 
    } 

    public function getDescription() 
    { 
    return $this->description; 
    } 

    public function setThumb($thumb) 
    { 
    $this->thumb = $thumb; 
    } 

    public function getThumb() 
    { 
    return $this->thumb; 
    } 

    public function setImg($img) 
    { 
    $this->img = $img; 
    } 

    public function getImg() 
    { 
    return $this->img; 
    } 

    public function setStatus(\Optime\AppStatusBundle\Entity\Status $status) 
    { 
    $this->status = $status; 
    } 

    public function getStatus() 
    { 
    return $this->status; 
    } 

    public function getCreated() 
    { 
    return $this->created; 
    } 

    public function getModified() 
    { 
    return $this->modified; 
    } 

    public function getPrizes() 
    { 
    return $this->prizes; 
    } 

    public function getOrderCat(){ 
     return $this->order_cat; 
    } 

    public function setOrderCat($order_cat){ 
     $this->order_cat = $order_cat; 
    } 

    static public function getListDQL() 
    { 
    return "SELECT cat FROM " . Category::getFQCN() . " cat 
         WHERE cat.status = 1"; 
    } 

    static public function getFQCN() 
    { 
    return 'Prizes\PrizesBundle\Entity\Category'; 
    } 
} 

這是我正在創建的形式

public function buildForm(FormBuilder $builder, array $options) 
{ 
    $query = new QueryBuilder($this->em); 
    $query->addSelect('s')->from(Status::getFQCN(), 's')->join('s.status_entity', 'se')->where("se.name = 'Prize'"); 
    $builder->add('status', 'entity', array ('class' => 'AppStatusBundle:Status', 'property' => 'name', 'query_builder' => $query, "required" => false, 'empty_value' => ' - SELECT - ')); 
    $builder->add('name', 'text', array ("required" => false)); 
    $builder->add('country', 'entity',array ('class' => 'CSCBundle:SystemCountry', 'property' => 'country.name', "required" => false, 'empty_value' => ' - SELECT - ')); 
    $builder->add('category', 'entity', array ('class' => 'PrizesBundle:Category', 'property' => 'name', "required" => false, 'empty_value' => ' - SELECT - ', 'query_builder' => 
       function(EntityRepository $er) { 
         return $er->createQueryBuilder('c')->join('c.status', 's')->where("s.name = 'Alive'") 
          ->orderBy('c.order_cat', 'ASC'); 
       },)); 
    $builder->add('brand', 'entity', array ('class' => 'PrizesBundle:Brand', 'property' => 'name', "required" => false, 'empty_value' => ' - SELECT - ')); 
} 

我曾經有

return "SELECT cat FROM " . Category::getFQCN() . " cat 
         WHERE cat.status = 1 ORDER BY cat.order_cat" 

代替本

SELECT cat FROM " . Category::getFQCN() . " cat 
         WHERE cat.status = 1 

但是當我嘗試,我得到[Semantical Error] line 0, col 108 near 'order_cat AS': Error: Class Prizes\PrizesBundle\Entity\Category has no field or association named order_cat

我在做什麼錯?我怎樣才能解決這個問題?我已經刪除了緩存並驗證了這些文件。

編輯:我需要一個對這兩個錯誤的答案。

回答

8

你的代碼看起來沒問題。你可以試試這個:

字段名爲order_catprivate所以它可能是由於反射的限制,這個字段不能直接訪問,但只能通過getters/setters訪問。

您是否嘗試過ORDER BY cat.orderCat

+0

我改變了它,是的,它的作品謝謝你。但第一個問題仍然存在 – Splendonia

+0

好的,但我不確定你指的是哪個其他錯誤。你只是提到了'order_cat'命令... –

+0

嗨,第一個是這樣的:錯誤:類獎品\ PrizesBundle \ Entity \ Category沒有名爲order_cat的字段或關聯,第二個在底部:[Semantic Error]行0,col 108在'order_cat AS'附近:錯誤:Class Prizes \ PrizesBundle \ Entity \ Category沒有字段或名爲order_cat的關聯,你的回答幫助我解決了第二個問題,但是第一個仍然是 – Splendonia

0

嘗試改變,以反映吸氣:

WHERE cat.status = 1 ORDER BY cat.OrderCat 
0

如果在檢查你的代碼後,你仍然可以得到這個錯誤,也許問題是從學說產生的代理類。或者如果您使用APC緩存,則必須清除它,才能使用新生成的代理類。

相關問題