Doctrine QueryBuilder returns QueryException

2019-08-19 04:32发布

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条回答
ゆ 、 Hurt°
2楼-- · 2019-08-19 04:58

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.

查看更多
登录 后发表回答