本文整理汇总了PHP中Doctrine\ORM\QueryBuilder::getDql方法的典型用法代码示例。如果您正苦于以下问题:PHP QueryBuilder::getDql方法的具体用法?PHP QueryBuilder::getDql怎么用?PHP QueryBuilder::getDql使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder::getDql方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assertValidQueryBuilder
protected function assertValidQueryBuilder(QueryBuilder $qb, $expectedDql)
{
$dql = $qb->getDql();
$q = $qb->getQuery();
$this->assertEquals($expectedDql, $dql);
}
示例2: addOrder
/**
* Build and add an oder field to the query builder.
*
* @param \Doctrine\Orm\QueryBuilder $qb
* @param mixed $order
* @return Gmg_Service_Abstract
*/
protected function addOrder($qb, $order)
{
// add the where expression to the query
// process the $order
if (is_string($order)) {
// straight DQL string
$qb->orderBy($order);
} elseif (is_array($order) && count($order)) {
// loop through each order clause supplied
foreach ($order as $col => $dir) {
// set the alias to the default
$alias = $this->alias;
// if col relates to Relation i.e. Role.id
// then set up the alias and column names (the join should have
// already been performed in the $where)
// TODO: this will cause an error if the column wasn't specified in the $where
if (strpos($col, '.') !== false) {
$parts = explode('.', $col);
$col = array_pop($parts);
$par = $this->alias;
// test for existing joins
$as = array();
foreach ($qb->getDQLPart('join') as $j) {
$as[] = $j;
}
foreach ($parts as $rel) {
$alias = strtolower($rel);
$jt = new Expr\Join(Expr\Join::LEFT_JOIN, $par . '.' . $rel, $alias);
if (!strpos($qb->getDql(), $jt->__toString()) !== false) {
$qb->leftJoin($par . '.' . $rel, $alias);
}
$par = $alias;
}
}
$qb->addOrderBy($alias . '.' . $col, $dir);
}
}
return $this;
}