大家好我在一个项目上工作有一个捆绑CustomerBundle当我调用一个函数后出现错误显示任何人都可以告诉我为什么这个错误会被解决..
message“:”序列化数据不支持资源。路径: Monolog \ Handler \ StreamHandler - > Symfony \ Bridge \ Monolog \ Logger - > Symfony \ Component \ Cache \ Adapter \ FilesystemAdapter - > Symfony \ Component \ Cache \ Adapter \ TraceableAdapter - > Symfony \ Component \ Cache \ DoctrineProvider - > Doctrine \ Common \ Annotations \ CachedReader - > Doctrine \ ORM \ Mapping \ Driver \ AnnotationDriver - > Doctrine \ Common \ Persistence \ Mapping \ Driver \ MappingDriverChain - > Doctrine \ ORM \ Configuration - > Doctrine \ ORM \ EntityManager - > CustomerBundle \库\ CustomerRepository” “class”:“JMS \ Serializer \ Exception \ RuntimeException”,
这是我的客户实体页面
/**
* @ORM\ManyToOne(targetEntity="CompanyBundle\Entity\Company", inversedBy="company_customer")
* @ORM\JoinColumn(name="company_id", referencedColumnName="id")
*/
private $companyId;
/**
* @var \DateTime
*
* @ORM\Column(name="created_time", type="datetimetz")
*/
private $createdTime;
/**
* @var \DateTime
*
* @ORM\Column(name="modified_time", type="datetime")
*/
private $modifiedTime;
/**
* @ORM\OneToMany(targetEntity="SalesBundle\Entity\SalesAccount", mappedBy="customerId" )
*/
private $sales_customer_id;
CustomerApiController控制器
namespace CustomerBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Component\HttpFoundation\Request;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\FOSRestController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use FOS\RestBundle\View\View;
use CustomerBundle\Entity\Customer;
class CustomerapiController extends FOSRestController
{
/**
* @Rest\Post("/api/customer")
*/
public function customerAction(Request $request)
{
$data = $this->getDoctrine()->getRepository(Customer::class);
$data->find(1);
return $data;
}
}
答案 0 :(得分:0)
我想你应该看看this post。类似的问题可以用同样的方法解决。
编写自定义存储库函数并执行以下操作而不是“find(1)”:
public function findFirstElement()
{
$qb = $this->createQueryBuilder('e');
$qb->where('e.id = 1');
return $qb->getQuery()->getArrayResult();
}