duanhe4267
2013-05-23 18:00
浏览 15
已采纳

Doctrine QueryBuilder返回QueryException

I'm trying to get my Page Entities using the Doctrine QueryBuilder. I have succesfully implemented the ORM and it generated my database without any trouble. Now that I want to grab the Entities from the database, it seems to return a QueryException

Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message 'SELECT page FROM Website\Model\Body\Page page WHERE page.isActive = 1' in path\to\orm\Doctrine\ORM\Query\QueryException.php:39 
Stack trace: 
#0 path\to\orm\Doctrine\ORM\Query\Parser.php(429): Doctrine\ORM\Query\QueryException::dqlError('SELECT page FRO...') 
#1 path\to\orm\Doctrine\ORM\Query\Parser.php(854): Doctrine\ORM\Query\Parser->semanticalError('Class 'Website\...', Array) 
#2 path\to\orm\Doctrine\ORM\Query\Parser.php(1529): Doctrine\ORM\Query\Parser->AbstractSchemaName() 
#3 path\to\orm\Doctrine\ORM\Query\Parser.php(1426): Doctrine\ORM\Query\Parser->RangeVariableDeclaration() 
#4 path\to\orm\Doctrine\ORM\Query\Parser.php(1168): Doctrine\ORM\Query\Parser->IdentificationVariableDeclaration() 
#5 path\to\orm\Doctrine\ORM\Query\Parser.php(757): Doctrine\ORM\Query\Parser->FromClause()
#6 path\to\ in path\to\orm\Doctrine\ORM\Query\QueryException.php on line 49

This piece of code causes the trouble

public function getActivePages()
{
    $qb = \WebTools\Doctrine\Doctrine::instance()->getQueryBuilder();
    $qb->select('page')
       ->from('Website\Model\Body\Page', 'page')
       ->where($qb->expr()->eq("page.isActive", true));
    $query = $qb->getQuery();
    $result = $query->getResult();
    \Doctrine\Common\Util\Debug::dump($result);
    die();
    return $result;
}

Any help is appreciated, thanks

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • douxiegan6468 2013-05-23 20:42
    最佳回答

    Try

    $qb->select('page')
       ->from('Page', 'page')
    

    or

     $qb->select('page')
       ->from('\Website\Model\Body\Page', 'page')
    

    and make sure your class is mapped by dotrine.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题