2

我的搜索方法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
        }
    }
}

但我就是不能 fetch $workers,我怎么能把它从search()to传递过来index.ctp

非常感谢!

4

2 回答 2

3

在这种情况下,您可以尝试使用 Session。

//在控制器1 $this->Session->write('worker', $workers);

//在控制器2 $workersData = $this->Session->read('worker');

于 2013-05-13T18:23:51.103 回答
0

是的,您可以按照以下语法使用

$this->redirect(array('controller' => 'workers', 'action' => 'index', 'pass' => 'param', 'pass1' => 'param1'));

有关更多详细信息,您可以使用doc

于 2013-05-13T12:38:06.107 回答