Posts

Showing posts with the label Cakephp

CakePHP Find Condition For A Query Between Two Dates

Answer : $conditions = array( 'conditions' => array( 'and' => array( array('Item.date_start <= ' => $date, 'Item.date_end >= ' => $date ), 'Item.title LIKE' => "%$title%", 'Item.status_id =' => '1' ))); Try the above code and ask if it not worked for you. Edit: As per @Aryan request, if we have to find users registered between 1 month: $start_date = '2013-05-26'; //should be in YYYY-MM-DD format $this->User->find('all', array('conditions' => array('User.reg_date BETWEEN '.$start_date.' AND DATE_ADD('.$start_date.', INTERVAL 30 DAY)'))); Here is CakePHP BETWEEN query example. I'm defining my arrays as variables, and then using those variables in my CakePHP find function call: // just return...

Best Way To Document Array Options In PHPDoc?

Image
Answer : A bit too late to the party but this is how I do it instead: /** * Class constructor. * * @param array $params Array containing the necessary params. * $params = [ * 'hostname' => (string) DB hostname. Required. * 'databaseName' => (string) DB name. Required. * 'username' => (string) DB username. Required. * 'password' => (string) DB password. Required. * 'port' => (int) DB port. Default: 1433. * 'sublevel' => [ * 'key' => (\stdClass) Value description. * ] * ] */ public function __construct(array $params){} Think it's quite clean and easy to understand what $params should be. I wrote a plugin for phpstorm that allows specifying keys like this: (basically just a slightly stricter version of @siannone's format) /** * @param array $arr = [ * 'fields' => [ // Defines the feilds t...