How to use AND and OR conditions in cakephp find function

Cakephp

Posted on 06 Nov 15 by Vickey
  619



In cakephp find function we add conditions like this

$Mymodeldata=$this->Mymodel->find('first', array(
	'conditions'=>array('Mymodel.column1' => 2,'Mymodel.column2' => 5)
	)
);

But in this code we have only 'AND' conditions. like in this sql query

'SELECT * FROM mytable WHERE column1=2 AND column2=5'

if you want to add 'AND' and 'OR' conditions both you can use the below code

$Mymodeldata=$this->Mymodel->find('first', array(
	'conditions'=>array(
		'OR'=>array(
			'Mymodel.column1' => 2,
			'Mymodel.column2' => 5
		),
		'AND'=>array(
			'Mymodel.column3'=>1
		)
	))
);

 


If this post help you reduce time to develop, you can help me to maintain this website :)
www.000webhost.com