2013-02-22 103 views
2

我的代码在我的控制器:选择所有

$categories = $this->getDoctrine()->getRepository('MyBundle:Categories')->findAll(); 

在默认情况下返回从我的表中的所有数据,但我想返回只记录其中collumn“ cenzored“是0.我怎样才能做到这一点,而不需要另一个实体?

我的表看起来是:

cid | integer | auto_increment 
name | varchar(50) 
cenzored | boolean 

回答

2

使用findBy代替,并添加一些信息为WHERE -clause使用数组:

[…]->findBy(array('cenzored' => false)); 
+2

是不是可以使用'[...] - > findByCenzored(false);'在这种情况下? – cheesemacfly 2013-02-22 21:32:18

+1

嘿@cheesemacfly绝对正确。在这种情况下它也会起作用。在属性名称具有一个或多个下划线的情况下它不起作用 - 仅作为注释。 – insertusernamehere 2013-02-22 21:38:18

+0

好吧,知道! :) – cheesemacfly 2013-02-22 21:40:24