php - CakePHP 2, CakePHP conditions, Dynamic condition on search, MySQL expression -


i trying build search query report in cakephp application. in query condition building go through if, else statements. on initial load of report want load pre-defined criteria , when user submit search conditions changed on selection.

this initial conditions

$conditions['report.expense_status'] = array('completed'); $conditions['date(report.created) >='] = "date_sub(now(), interval 2 month)"; 

when user search conditions should update below.

if ($this->request->is('post')) {      $search = $this->request->data('report');     if( strlen($search['from']) > 0 ){                         $conditions['date(report.created) >='] = date( 'y-m-d',strtotime($search['from']) );     } } 

but initial condition code output sql expression below , not getting populate result.

date(`report`.`created`) >= 'date_sub(now(), interval 2 month)' 

it adding quotes expression.

how should prevent adding quotes around condition?

form:

<?php echo $this->form->create('report', array('action' => 'index')); ?> <div>     <?php      echo $this->form->input('keyword');     echo $this->form->input('status',                             array(                                 'options' => $status,                                 'multiple'=> 'false'                             )                           );     echo $this->form->input('child',                             array(                                 'options' => $children,                                 'multiple'=> 'false'                             )                            );     echo $this->form->input('from',                             array(                                 'id' => 'report_from'                             )                         );     echo $this->form->input('to',                             array(                                 'id' => 'report_to'                             )                         );     ?>     <div class="footer">         <div>             <input type="submit" value="search" name="action">             <input type="button" value="cancel" name="action">         </div>     </div> </div> <?php echo $this->form->end(); ?> 


Comments