Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 错误:方法原则\ORM\Query\Expr\From::\uu toString()不能在symfony 2应用程序中引发异常_Php_Mysql_Symfony_Doctrine Orm - Fatal编程技术网

Php 错误:方法原则\ORM\Query\Expr\From::\uu toString()不能在symfony 2应用程序中引发异常

Php 错误:方法原则\ORM\Query\Expr\From::\uu toString()不能在symfony 2应用程序中引发异常,php,mysql,symfony,doctrine-orm,Php,Mysql,Symfony,Doctrine Orm,请根据产品实体所属的部门获取产品实体,但该部门实体与产品实体没有直接关系。以这种方式,产品是部门的伟大后代 部门->类别->集团->产品 部门存储库 public function findDepartmentProduct($id) { return $this ->createQueryBuilder(['p', 'c', 'gc', 'ggc']) ->select(['p', 'c', 'gc', 'ggc']) -&g

请根据产品实体所属的部门获取产品实体,但该部门实体与产品实体没有直接关系。以这种方式,产品是部门的伟大后代 部门->类别->集团->产品

部门存储库

public function findDepartmentProduct($id)
{
    return $this
        ->createQueryBuilder(['p', 'c', 'gc', 'ggc'])
        ->select(['p', 'c', 'gc', 'ggc'])
        ->from('Parent', 'p')
        ->leftJoin('p.children', 'c')
        ->leftJoin('c.grandchildren', 'gc')
        ->leftJoin('gc.greatgrandchildren', 'ggc')
        ->where('p.id = :id')
        ->andWhere('ggc.expire = :no')
        ->setParameter('no',0)
        ->setParameter('id', $id)
        ->getQuery();
   }
控制器:

  /**
 * @Route("/department/{id}", name = "department")
 */
public function departmentAction(Request $request,$id)
{
    $Department = $this->getDoctrine()->getRepository('AppBundle:Department');
    $department = $Department->find($id);

    $Product = $this->getDoctrine()->getRepository('AppBundle:Product');
    $customersChoiceProducts = $Product->mostView('20');


    $query = $Department->findDepartmentProduct($id);

    $paginator  = $this->get('knp_paginator');
    $pagination = $paginator->paginate(
        $query, /* query NOT result */
        $request->query->getInt('page', 1)/*page number*/,
        8/*limit per page*/
    );

    return $this->render('default/department.html.twig', array(
        'pagination' => $pagination,
        'department'=>$department,
        'customersChoiceProducts'=>$customersChoiceProducts,
    ));
}
视图:


    {%用于分页%中的产品}
  • {%endfor%}
然后我运行我得到错误的代码

错误:方法原则\ORM\Query\Expr\From::\uu toString()不能引发异常 500内部服务器错误-FatalErrorException

这:

应为:

->from('YourNamespaceYourBundle:Parent', 'p')
或:


当然,要为您的应用程序提供正确的名称空间或包名称。

查看部门存储库`namespace AppBundle\repository;使用条令\ORM\EntityRepository;使用AppBundle\Entity\Department;类DepartmentRepository扩展EntityRepository{public function findDepartmentProduct($id){return$this->createQueryBuilder(['p','c','gc','ggc'])->select(['p','c','gc','ggc'])->from('AppBundle:Department','p')->leftJoin('p.Category','c')->leftJoin('c.Group','gc')->leftJoin('gc.Product','ggc')->getQuery();}`
->from('Parent', 'p')
->from('YourNamespaceYourBundle:Parent', 'p')
->from('YourNamespace\YourBundle\Parent', 'p')