Reputation: 662
How can I set an integer variable with a wildcard for all records. The reason is I need all records sometimes if the id's are not set . My wildcard isnt working. I currently use an if condition to test if the id is set and there is 4 combinations with 2 variables.
The LIKE option didnt work for me either.
Is there a way to assign a value to the variable to search and this equated to all values like . in sql? For example
$tutorId='*';
$paycycleId='*';
$timesheet=$this->TimeSheet->find('all',array(
'conditions'=> array ('TimeSheet.tutor_id'=>$tutorId,'TimeSheet.period_start_date'=>$paycycleId ),
'order' => array('TimeSheet.invoice DESC')) );
Upvotes: 0
Views: 513
Reputation: 11693
If you want wild search or select All records then use :
UPDATED Added BETTER way
//BETTER way ->
$conditionsArr = array();
if(CONDITION_SATISFIED){
$conditionsArr=array('TimeSheet.tutor_id'=>$tutorId,
'TimeSheet.period_start_date'=>$paycycleId
);
}
$timesheet=$this->TimeSheet->find('all',
array(
'conditions'=> $conditionsArr,
'order' => array('TimeSheet.invoice DESC')
)
);
//PREVIOUS WAY ->
$conditionsArrEmpty=array();
$conditionsArr=array('TimeSheet.tutor_id'=>$tutorId,
'TimeSheet.period_start_date'=>$paycycleId
);
//With Wildcard (Select All records)
$timesheet=$this->TimeSheet->find('all',
array(
'conditions'=> $conditionsArrEmpty,
'order' => array('TimeSheet.invoice DESC')
)
);
//With Acutal conditions
$timesheet=$this->TimeSheet->find('all',
array(
'conditions'=> $conditionsArr,
'order' => array('TimeSheet.invoice DESC')
)
);
Upvotes: 1