php - CakePHP: Filter view on multiple criteria only returns one result -


i'm trying build rudimentary search feature cakephp application. there 2 fields need searchable. have code in controller take 2 search values form:

$options = array('model.id' => $this->request->data['model']['id'],     'model.field2' => $this->request->data['model']['field2']);  $this->set('views', $this->paginator->paginate('model', $options)); 

both of these inputs come dropdown lists , both required. right now, when run search, returns 1 result, first selectable option in field2 dropdown, so:

id   field2 1    value1  or  id   field2 2    value1 

if search other value in field2, no result. if comment out dropdown field2 , search id, rows id (around 500, expected). why result set empty when search on id , value other value1 in second dropdown?

the $options array passed argument paginate can contain multiple keys, similar ones used model->find()

first build $conditions array

$conditions = array('model.id' => $this->request->data['model']['id'],     'model.field2' => $this->request->data['model']['field2']); 

then $options

$options['conditions'] = $conditions 

then pass paginate

$this->set('views', $this->paginator->paginate('model', $options)); 


update:

$conditions = array('model.id' => $this->request->data['model']['id'],         'model.field2' => $this->request->data['model']['field2']); $options['conditions'] = $conditions;  $this->paginator->settings = $options; $data = $this->paginator->paginate('model');  $this->set('views', $data); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -