我的数据库中有一张表:文章
它有行:id,title,num
我正在尝试在Doctrine 2中进行查询,以显示带有max" num"的文章。号。
我需要帮助才能正确使用"其中"在我的查询到articleController 或者如果你有更好的解决方案
<?xml version="1.0" encoding="UTF-8"?>
<project name="Test" default="build">
<!-- ============================================ -->
<!-- Target: start -->
<!-- ============================================ -->
<target name="start">
<echo msg="Start build" />
</target>
<!-- ============================================ -->
<!-- Target: prepareDirectory -->
<!-- ============================================ -->
<target name="prepareDirectory" depends="start">
<echo msg="Making directory build ./build" />
<mkdir dir="./build" />
<echo msg="Making directory install ./install" />
<mkdir dir="./install" />
</target>
<!-- ============================================ -->
<!-- Target: build -->
<!-- ============================================ -->
<target name="build" depends="prepareDirectory">
<echo msg="Copying files to build directory..." />
<echo msg="Copying ./about.php to ./build directory..." />
<copy file="./about.php" tofile="./build/about.php" />
<echo msg="Copying ./browsers.php to ./build directory..." />
<copy file="./browsers.php" tofile="./build/browsers.php" />
<echo msg="Copying ./contact.php to ./build directory..." />
<copy file="./contact.php" tofile="./build/contact.php" />
</target>
</project>
答案 0 :(得分:0)
一种可能的解决方案
public function articleAction() {
$repository = $this->getDoctrine()->getRepository('appBundle:Article');
$article = $repository->createQueryBuilder('a')
->select('a.id','a.title','a.num')
->orderBy('a.num', 'DESC')
->getQuery()
->getOneOrNullResult();
return $this->render('appBundle:articles:article.html.twig', array(
'article'=>$article)
);
}