Reputation: 35
I have a search method in my WorkersController.php
like following:
public function search() {
$conditions = array();
if(!empty($this->request->data)){
foreach($this->request->data['Search'] as $field => $search_condition ) {
if(!empty($search_condition))
$conditions["$field LIKE "] = "%$search_condition%";
}
}
if(!empty($conditions)){
$this->Worker->recursive = 0;
$workers = $this->Worker->find('all',array('conditions' => $conditions));
}
$this->redirect(array('action' => 'index','search' ));
}
IN the method I call redirect()
, then the page goes to index.ctp
, where I want to fetch $workers
like this:
if($this->request->params['pass']==array('search')){
if (empty($workers)){
echo('No result found!');
}else{
foreach ($workers as $worker){
//do something
}
}
}
But I just can't fetch $workers
, how can I pass it from search()
to index.ctp
?
Thanks a lot!
Upvotes: 2
Views: 4905
Reputation: 189
You could try and use Session for this case.
//in controller1 $this->Session->write('worker', $workers);
//in controller2 $workersData = $this->Session->read('worker');
Upvotes: 3