我,正在创建一个带有标签和排序顺序的市场,标签工作正常,但是当我有排序代码时,它说:
Catchable Fatal Error: Object of class \Entity\Category could not beconverted to
string in \vendor\doctrine\orm\lib\Doctrine\ORM\Query\Expr.php line 568
我在google上搜索,没有人遇到同样的问题?我的代码:
public function tagAction($tag, $sort) {
$rep = $this->getDoctrine()
->getRepository('RSHubMarketplaceBundle:Modification');
$tags = $this->getDoctrine()
->getRepository('RSHubMarketplaceBundle:Category')
->findAll();
if($tag == -1){
$stags = $tags;
} else {
$tag = $this->getDoctrine()
->getRepository('RSHubMarketplaceBundle:Category')
->find($tag);
$stags = array($tag);
}
switch ($sort) {
case 'popularity':
$mods = $rep->getByPopularity( array($tag));
break;
case 'downloads':
$mods = $rep->getByDownloads( array($tag));
break;
case 'newest':
$mods = $rep->getByNewest(array($tag));
break;
case 'name':
$mods = $rep->getByName( array($tag));
break;
}
return $this->render('RSHubMarketplaceBundle:Marketplace:index.html.twig',
array('categories' => $tags, 'mods' =>$mods,
'tag' => $tag));
}
以及我遇到问题的方法:
public function getWithCategoriesOrdered(array $nom_categories, $orderCol, $order) {
$qb = $this->createQueryBuilder('a');
$qb->join('a.categories', 'c')
->where($qb->expr() // HERE
->in('c.name', $nom_categories));
$qb->add('orderBy', 'a.'.$orderCol.' '.$order);
return $qb->getQuery()
->getResult();
}