为什么我在symfony中收到'Entity Not Found'错误

时间:2015-07-04 09:45:42

标签: symfony

我正在编写Web服务,这在localhost上工作正常,但是当在服务器上传时,我收到此错误:

  

{     “代码”:500,     “消息”:“找不到实体。”   }

所有实体都在那里,但我仍然收到此错误 这是我的控制器功能:

public function getSendEmailBusinessAction($bussId, $userId)
{

    $em = $this->getDoctrine()->getManager();

    $query1 = $em->createQuery('SELECT list.email from StreetBumbApiBundle:BussOwner list WHERE list.id = :bussId')
        ->setParameter("bussId", $bussId);
    $list2 = $query1->getResult();
    $email = $list2[0]['email'];

    $query = $em->createQuery('SELECT list from StreetBumbApiBundle:UserOffers list WHERE list.userId = :userId')
        ->setParameter("userId", $userId);
    $list = $query->getResult();

   $userEmail =  $list[0]->getUserId()->getUsername();
   $offerDescription = $list[0]->getOfferId()->getDescription();
   $offerDate = $list[0]->getOfferId()->getExpiryDate();
   $offerPhno = $list[0]->getOfferId()->getPhno();

    $message = \Swift_Message::newInstance()
        ->setSubject('User and offer details selected by user')
        ->setFrom('admin@mail.com')
        ->setTo($email)
        ->setBody(
            "User Email Id: $userEmail",
            "Offer Description:  $offerDescription",
            "Offer Date and Time:  $offerDate",
            "Phone number:  $offerPhno"
        )

    ;
    $this->get('mailer')->send($message);

    if ($list == 0) {
        $view = View::create();
        $response[]=array("code"=>200,"message"=>"Data Not Found","data"=>"");
        $view->setData($response)->setStatusCode(200);
        return $view;
    }
    $response[]=array("code"=>200,"message"=>"Success","data"=>$list);
    $view = View::create();
    $view->setData($response)->setStatusCode(200);
    return $view;

}

谁能告诉我哪里有问题?

1 个答案:

答案 0 :(得分:0)

似乎此错误“未找到实体”是常见错误。

答案是:您正在尝试get某些不存在或在引用表中删除的行。

检查是否:

上面的代码中返回了

getUserId() & getOfferId(),相应的条目位于用户和商品表

你也可以尝试一下。如果我是对的,这应该有效:

if ($list[0]->getUserId()) {
    $userEmail =  $list[0]->getUserId()->getUsername();
}
if ($list[0]->getOfferId()) {
    $offerDescription = $list[0]->getOfferId()->getDescription();
    $offerDate = $list[0]->getOfferId()->getExpiryDate();
    $offerPhno = $list[0]->getOfferId()->getPhno();
}