Posts

Showing posts from March, 2013

CakePHP: COUNT data and GROUP BY date

Image
Easily deploy an SSD cloud server on @DigitalOcean in 55 seconds. Sign up using this link and receive $100 in cloud credits: https://m.do.co/t/335732d1df0b Goal: Count Tip Offs created per day for a month to use for graph Problem: created field name is in datetime format: Y-m-d H:i:s Solution: format SQL Query date: DATE_FORMAT(TipOff.created, '%Y-%m-%d') Inside the function of controller <?php $ tipOffsMonthly = $ this -> TipOff -> find( ' all ' , array ( ' conditions ' => array ( ' AND ' => array ( ' TipOff.electric_cooperatives_id ' => AuthComponent :: User ( ' electric_cooperatives_id ' ) , ' TipOff.created BETWEEN ? AND ? ' => array ( $ first_day , $ last_day ) ) ) ,

CakePHP : Load Model from other Controller

In your Controller were you want to load the model. <?php     App : : import ( 'Controller' ) ;    class ReportsController extends AppController {                 public function other_reports ( ) {            //this will load other model            $ this - > loadModel ( 'OtherModel' ) ;            $otherModels = $ this -> OtherModel - > find ( 'all' ) ;            $ this - > set ( 'otherModels' , $otherModels ) ;      }          } ?>