0

我,正在创建一个带有标签和排序顺序的市场,标签工作正常,但是当我有排序代码时,它说:

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

1 回答 1

0

有两种方法

a)在返回其名称的类别实体中添加 __toString() 方法

b) 假设 $nom_categories 是一个类别,只需在查询表达式中传递 $nom_categories->getName()

在这种错误(使用外部库)中,您需要调试并仔细检查堆栈跟踪

于 2013-08-30T15:33:17.763 回答