这就是我想做的:
$query = $repository->createQueryBuilder('c')
->where('c.categoryParentid = ?', $pcategory->getcategoryId())
->orderBy('c.categoryId', 'ASC')
->getQuery();
$childcategories = $query->getResult();
$pcategory->getcategoryId()
是一个整数。在哪里,这是正确的吗?我收到此错误:
ContextErrorException: Warning: get_class() expects parameter 1 to be object, integer given in /Applications/mampstack-5.4.20-0/apache2/htdocs/reuzze/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Expr/Base.php line 92
我以前没有使用过这种语法,但是Symfony文档有使用查询生成器的示例,它们显示了如下所示的内容:
$query = $repository->createQueryBuilder('c')
->where('c.categoryParentid = :pcategory')
->setParameter('pcategory', $pcategory->getcategoryId())
->orderBy('c.categoryId', 'ASC')
->getQuery();
你也可以使用EntityRepository::findBy()方法(在Symfony 2.x文档中概述),它允许你指定搜索条件和排序。
例如
$childCategories = $repository->findBy(array(
'categoryParentId' => $pcategory->getCatagoryId()
),
array(
'categoryId' => 'ASC'
)
);