How to Make a Query in CakePHP?

CakePHP

To Query from Table in CakePHP we can use the below code. We can also Query like ORDER_BY, Select Table FIELDS etc.

# Find Order from Order Table in CakePHP

$this->Order->find('all', array(
   'recursive' => -1,
   'conditions'=>array( 'Order.id'=>1 ),
   'fields' => array( 'Order.date', 'Order.id', 'Order.total'),
   'order' => array('Order.date' => 'DESC'),
));


# For Order By filter in Querry, we can use.

   'order' => array('Order.date' => 'DESC'),
or,
   'order' => array('Order.date DESC'),
or,
   'order' => 'Order.date ASC',

Leave a Comment