我的WorkersController.php
中有一个搜索方法,如下所示:
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' ));
}
在我调用redirect()
的方法中,页面转到index.ctp
,我想在此处抓取$workers
:
if($this->request->params['pass']==array('search')){
if (empty($workers)){
echo('No result found!');
}else{
foreach ($workers as $worker){
//do something
}
}
}
但我无法抓取$workers
,如何将其从search()
传递到index.ctp
?
非常感谢!
答案 0 :(得分:3)
您可以尝试使用Session来处理此案例。
//在controller1中 $ this-> Session-> write('worker',$ workers);
//在controller2中 $ workersData = $ this-> Session-> read('worker');
答案 1 :(得分:0)
是的,您可以按照以下语法使用
$this->redirect(array('controller' => 'workers', 'action' => 'index', 'pass' => 'param', 'pass1' => 'param1'));
有关详细信息,请使用doc