我使用扩展生成器为我的扩展生成基础。但现在我想修改我的 listAction() 方法的输出:
public function listAction() {
$rooms = $this->roomRepository->findAll();
$this->view->assign('rooms', $rooms);
}
是否可以添加 where 语句以不接收表“Rooms”中的所有行?
You can just add custom methods into your repository for advanced querying the DB like described in the blog post
sample:
public function findRecentByBlog(Tx_BlogExample_Domain_Model_Blog $blog, $limit = 5) {
$query = $this->createQuery();
return $query->matching($query->equals('blog', $blog))
->setOrderings(array('date' => Tx_Extbase_Persistence_QueryInterface::ORDER_DESCENDING))
->setLimit((integer)$limit)
->execute();
}
so you can use it in controller like:
$posts = $this->postRepository->findRecentByBlog($blog, 3);