Cakephpdocs 46

CategoryCakePHP functions - find with conditions
Code ExamplesExample: $this->Post->find('all',array('conditions'=>array('User.id'=>'<> 1'))); This is somewhat similar to sql's where clause. Cake parses other SQL expressions, which include LIKE, BETWEEN, and REGEX, but you must have a space between the operator and the value. You can search for date or datetime fields by enclosing the field name in the SQL DATE() parameter. Another example: (AND case) $this->Post->find('all',array('conditions'=> array('User.id'=>1, 'DATE(Post.date)'=>'CURDATE()'))); Another example: (OR case) $this->Post->find('all',array('conditions'=>array( 'or'=>array( 'User.id'=>1,'DATE(Post.date)'=>'CURDATE()' ) ))); Another example - search multiple values of a field: $this->Post->find('all',array('conditions'=> array('User.id'=>array(1,2,5,10)) )); Another example: $this->Post->find('all',array('order'=>'date DESC', 'limit'=>5,'recursive'=>0));
Test Code
Links
Remarks
Cancel