本文整理汇总了PHP中Doctrine\ORM\Query::getSingleResult方法的典型用法代码示例。如果您正苦于以下问题:PHP Query::getSingleResult方法的具体用法?PHP Query::getSingleResult怎么用?PHP Query::getSingleResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Query
的用法示例。
在下文中一共展示了Query::getSingleResult方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSingleResult
private function getSingleResult(Query $query)
{
try {
$result = $query->getSingleResult();
} catch (NonUniqueResultException $e) {
$result = null;
} catch (NoResultException $e) {
$result = null;
}
return $result;
}
示例2: single
/**
* Returns single result from query
*
* @access public
* @param bool $bAsArray
* @return mixed
* @throws Doctrine\ORM\NonUniqueResultException
* @since 1.0.0-alpha
* @version 1.0.0-alpha
*/
public function single($bAsArray = FALSE)
{
$this->limit(1);
try {
if ($bAsArray) {
self::$mResult = $this->oQuery->getSingleResult(2);
} else {
self::$mResult = $this->oQuery->getSingleResult();
}
} catch (Doctrine\Orm\NoResultException $e) {
self::$mResult = FALSE;
}
return self::$mResult;
}
示例3: tagAction
/**
* @route: blog_tag
* Tag Controller
*/
public function tagAction($slug)
{
$em = $this->getEm();
$query = new Query($em);
$query->setDQL(
'SELECT t
FROM Bundle\BlogBundle\Entity\Tag t WHERE t.slug = ?1'
);
$query->setParameter(1, $slug);
$tag = $query->getSingleResult();
return $this->render('BlogBundle:Blog:tag.html.twig', array(
'tag' => $tag,
'posts' => $tag->getPosts()
));
}
示例4: doQueryResult
public static function doQueryResult(\Doctrine\ORM\Query $query, $resultType)
{
switch ($resultType) {
case ResultType::ArrayType:
return $query->getArrayResult();
break;
case ResultType::ObjectType:
return $query->getResult();
break;
case ResultType::SingleObjectType:
return $query->getSingleResult();
break;
case ResultType::SingleArrayType:
return $query->getSingleResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
break;
default:
throw new \Exception("Not a valid ResultType.");
}
}