获取数据时symfony2中的语义错误

时间:2015-06-11 08:23:09

标签: symfony

我正在尝试编写一个Web服务,以嵌套数组方式获取该类别下的类别列表和所有业务。

我收到一个语义错误说:

{
  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;
}

如果有人有想法,请指导.. Thanx

更新 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;
}

}

1 个答案:

答案 0 :(得分:1)

我认为问题是实体名称中的下划线。

Doctrine的命名约定是使用CamelCase,然后将其转换为数据库中的下划线。由于这种幕后魔术,下划线可能会导致实体名称出现问题。

尝试将实体类名称更改为BussOwner并在控制器中调用它。如果您无法更改表名,则可以通过将实体注释修改为:

来处理此问题
@ORM\Table(name="buss_owner")
相关问题