Skip to main content

Posts

Showing posts from August, 2012

CakePHP Complex Find Conditions

Today we are going to discuss over complex find conditions using multiple 'AND' and 'OR' operators.   I was to write a CakePHP find condition for following query : Select * from Quarter where Quarter.status = 1 AND ((Quarter.start_date >= '2012-04-01' AND Quarter.end_date <= '2012-06-30') OR (Quarter.start_date >= '2012-07-01' AND Quarter.end_date <= '2012-09-30')) ; It's not that typical but typical enough to understand the concept. First I wrote this query : $conditions = array(                 'conditions' => array(                                 'AND' => array(                         ...

CakePHP Auth Component Implementation

First time I was using Auth component of CakePHP and it took me around 2 complete days to fully understand Auth component and implement it. Documenation is also bit confusing on http://book.cakephp.org/1.3/ . I am writing this post for my future reference as well as for those who are having doubts with Auth component. Let's start 1) Very first step is to include Auth component in components array of AppController. As you know for controllers we do most of the common stuff in AppController. app_controller.php   var $components = array('Auth'); 2) If you wanna customize Auth component messages and variables use beforeFilter() method for that, as :       app_controller.php function beforeFilter() {                                  //it would load User model dynamically. Discussed in detail in step 4 ...