gpt4 book ai didi

php - 错误:方法 Doctrine\ORM\Query\Expr\From::__toString() 不得在 symfony 2 应用程序中抛出异常

转载 作者:行者123 更新时间:2023-11-28 23:37:40 25 4
gpt4 key购买 nike

Pls i need to fetch the product entity based on the department it belong to but the department entity does not have a direct relationship with the product entity. Product is the great grand child of department in this manner DEPARTMENT-> CATEGORY-> GROUP-> PRODUCT.

部门资料库

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();
}

Controller :

  /**
* @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,
));
}

查看:

<div class="link">
<ul>
{% for product in pagination %}
<li >
<a href="/brows/{{ product.id }}">
<span> <img src="{{ vich_uploader_asset(product, 'frontImageFile') }}" alt="" style="height:290px"></span>
<h2 class="title">
<span class="brand">{{ product.brand.name |title}}</span>
<span class="name">{{ product.name|title }}</span>
</h2>
<span class="price-box">
<span>
<span data-currency-iso="NGN">₦</span>
<span data-price="{{ product.price }}">{{ product.price }}</span>
</span>
</span>
</a>
</li>
{% endfor %}
</ul>
</div>

然后我运行代码我得到了错误

Error: Method Doctrine\ORM\Query\Expr\From::__toString() must not throw an exception 500 Internal Server Error - FatalErrorException

最佳答案

这个:

->from('Parent', 'p')

应该是:

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

或者:

->from('YourNamespace\YourBundle\Parent', 'p')

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

关于php - 错误:方法 Doctrine\ORM\Query\Expr\From::__toString() 不得在 symfony 2 应用程序中抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35353459/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com