2015-06-11 22 views
0

我正在嘗試編寫一個Web服務以嵌套數組方式獲取該類別下的所有業務。在獲取數據時symfony2中的語義錯誤

我得到一個語義錯誤說:

{ 
    code: 500 
    message: "[Semantical Error] line 0, col 14 near 'StreetBumbApiBundle:Buss_owner': Error: Class 'StreetBumb\ApiBundle\Entity\Buss_owner' is not defined." 
} 

我已經在控制器中定義的實體,我不知道爲什麼它顯示此錯誤。

這是我的控制器的功能看起來像:

public function getCategoryAction(){ 

    $em = $this->getDoctrine()->getEntityManager(); 
    $pro = $em->getRepository('StreetBumbApiBundle:Category') 
     ->getBusinessByCategory(); 
    //return $pro; 
    $i = 0; 
    foreach($pro as $p) 
    { 
     $data['category'][$i]['id'] = $p->getId(); 
     $data['category'][$i]['Name'] = $p->getCatName(); 
     //$result[$i] = $p->getId(); 

     $catId = $p->getId(); 

     $business = $em->createQuery('SELECT b FROM StreetBumbApiBundle:Buss_owner b WHERE b.catId = :catId')->setParameter('catId', $catId); 
     $result = $business->getResult(); 
     foreach($result as $r) 
     { 
      $data['business'][$i]['id'][] = $r->getId(); 
     } 
     $i++; 

    } 
    return $data; 
} 

請指導,如果任何人有想法..感謝名單

UPDATE: Buss_owner實體:

<?php 

namespace StreetBumb\ApiBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 

/** 
* Buss_owner 
* 
* @ORM\Table() 
*  @ORM\Entity(repositoryClass="StreetBumb\ApiBundle\Entity\Buss_ownerRepository") 
*/ 
class Buss_owner 
{ 
/** 
* @var integer 
* 
* @ORM\Column(name="id", type="integer") 
* @ORM\Id 
* @ORM\GeneratedValue(strategy="AUTO") 
*/ 
private $id; 

/** 
* @var string 
* 
* @ORM\Column(name="name", type="string", length=50) 
*/ 
private $name; 

/** 
* @var string 
* 
* @ORM\Column(name="email", type="string", length=255) 
*/ 
private $email; 

/** 
* @var integer 
* 
* @ORM\Column(name="phno", type="integer") 
*/ 
private $phno; 

/** 
* @var string 
* 
* @ORM\Column(name="address", type="string", length=255) 
*/ 
private $address; 

/** 
* @var string 
* 
* @ORM\Column(name="password", type="string", length=255) 
*/ 
private $password; 

/** 
* @var string 
* 
* @ORM\Column(name="fbId", type="integer") 
*/ 
private $fbId; 

/** 
* @var string 
* 
* @ORM\Column(name="uniqueId", type="string", length=255) 
*/ 
private $uniqueId; 

/** 
* @var integer 
* 
* @ORM\Column(name="catId", type="integer") 
* @ORM\ManyToMany(targetEntity="Category", mappedBy="Buss_owner") 
*/ 
private $catId; 

public function __construct() { 
    $this->catId = new \Doctrine\Common\Collections\ArrayCollection(); 
} 
/** 
* Get id 
* 
* @return integer 
*/ 
public function getId() 
{ 
    return $this->id; 
} 

/** 
* Set name 
* 
* @param string $name 
* @return Buss_owner 
*/ 
public function setName($name) 
{ 
    $this->name = $name; 

    return $this; 
} 

/** 
* Get name 
* 
* @return string 
*/ 
public function getName() 
{ 
    return $this->name; 
} 

/** 
* Set email 
* 
* @param string $email 
* @return Buss_owner 
*/ 
public function setEmail($email) 
{ 
    $this->email = $email; 

    return $this; 
} 

/** 
* Get email 
* 
* @return string 
*/ 
public function getEmail() 
{ 
    return $this->email; 
} 

/** 
* Set phno 
* 
* @param integer $phno 
* @return Buss_owner 
*/ 
public function setPhno($phno) 
{ 
    $this->phno = $phno; 

    return $this; 
} 

/** 
* Get phno 
* 
* @return integer 
*/ 
public function getPhno() 
{ 
    return $this->phno; 
} 

/** 
* Set address 
* 
* @param string $address 
* @return Buss_owner 
*/ 
public function setAddress($address) 
{ 
    $this->address = $address; 

    return $this; 
} 

/** 
* Get address 
* 
* @return string 
*/ 
public function getAddress() 
{ 
    return $this->address; 
} 

/** 
* Set catId 
* 
* @param integer $catId 
* @return Buss_owner 
*/ 
public function setCatId($catId) 
{ 
    $this->catId = $catId; 

    return $this; 
} 

/** 
* Get catId 
* 
* @return integer 
*/ 
public function getCatId() 
{ 
    return $this->catId; 
} 

/** 
* Set password 
* 
* @param string $password 
* @return Buss_owner 
*/ 
public function setPassword($password) 
{ 
    $this->password = $password; 

    return $this; 
} 

/** 
* Get password 
* 
* @return string 
*/ 
public function getPassword() 
{ 
    return $this->password; 
} 

/** 
* Set uniqueId 
* 
* @param string $uniqueId 
* @return Buss_owner 
*/ 
public function setUniqueId($uniqueId) 
{ 
    $this->uniqueId = $uniqueId; 

    return $this; 
} 

/** 
* Get uniqueId 
* 
* @return string 
*/ 
public function getUniqueId() 
{ 
    return $this->uniqueId; 
} 

/** 
* Set fbId 
* 
* @param integer $fbId 
* @return Buss_owner 
*/ 
public function setFbId($fbId) 
{ 
    $this->fbId = $fbId; 

    return $this; 
} 

/** 
* Get fbId 
* 
* @return integer 
*/ 
public function getFbId() 
{ 
    return $this->fbId; 
} 

} 
+0

請向我們顯示您的Buss_owner實體。 – BentCoder

+0

@BentCoder用'Buss_owner'實體更新了我的問題 – Geetika

回答

1

我相信問題是實體名稱中的下劃線。

Doctrine的命名約定是使用CamelCase,然後將其轉換爲數據庫中的下劃線。由於這種幕後魔法,下劃線會導致實體名稱出現問題。

嘗試更改實體類名稱爲BussOwner並在控制器中調用此名稱。如果您無法更改表名,則可以通過修改實體註釋來處理此問題:

@ORM\Table(name="buss_owner")