2013-05-18 71 views
4

如何編寫查詢像doctrine2邏輯或doctrine2 getRepository-> findBy()

SELECT * from table where field = value1 or field = value2

我發現像

$em->getRepository('myentitity') 
      ->findBy(
       array('field' => 'value1','field'=>'value2'),  // $where 
      ); 

但我認爲這是和..請建議me 謝謝

+0

這將幫助:HTTPS://doctrine-orm.readthedocs.org/en/latest /reference/working-with-objects.html?highlight=getRepository –

+0

@NiladriDas我已經看過那裏,但不能得到我想要的 – alwaysLearn

+0

請參閱條件運算符http://docs.doctrine-project.org/projects/doctrine-mongodb -odm/en/latest/reference/query-builder-api.html#conditional-operators你可以用'in'來查看這個頁面http://stackoverflow.com/questions/9259089/doctrine-findby-with-或條件 –

回答

10

試試這個

$em->getRepository('myentitity') 
     ->findBy(
      array('field' =>array('value1','value2'))  // $where 
     ); 

如果傳遞值的數組學說將查詢轉換成WHERE場(..)查詢自動: