可捕获的致命错误:类的对象<;类>;无法转换为..中的字符串..vendor doctrineorm


Catchable Fatal Error: Object of class <Class> could not be converted to string in ...vendordoctrineormlibDoctrineORMQueryExpr.php line 568

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

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

我在谷歌上搜索,没有人有同样的问题?我的代码:

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

有两种方式

a) 在返回其名称的Category Entity中添加__toString()方法

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

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