在CakePHP 3项目中,我想在我的控制器中运行一个选择。用户可以为选择选择不同的过滤条件。如果没有选择条件,我在选择中不需要它。
现在我有类似的东西
$where = [];
if ( ! empty($this->request->data['fcontact_id'])){
$where['Histories.contact_id'] = $this->request->data['fcontact_id'];
}
if ( ! empty($this->request->data['fuser_id'])){
$where['Histories.user_id'] = $this->request->data['fuser_id'];
}
if ( ! empty($this->request->data['fgroup_id'])){
$where['Histories.group_id'] = $this->request->data['fgroup_id'];
}
$histories = $this->Histories->find()->where($where);
有没有更好的方法呢?
答案 0 :(得分:0)