Cakephp PHP如何将参数从一个控制器动作传递到另一个视图
我在我的Cakephp PHP如何将参数从一个控制器动作传递到另一个视图,cakephp,redirect,params,Cakephp,Redirect,Params,我在我的WorkersController.php中有一个搜索方法,如下所示: public function search() { $conditions = array(); if(!empty($this->request->data)){ foreach($this->request->data['Search'] as $field => $search_condition ) { if(!empty
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
非常感谢 是,您可以按照以下语法使用
$this->redirect(array('controller' => 'workers', 'action' => 'index', 'pass' => 'param', 'pass1' => 'param1'));
有关更多详细信息,您可以使用您可以尝试在本案例中使用Session //在控制器1中 $this->Session->write($worker',$workers) //在控制器2中
$workersData=$this->Session->read('worker') 好的,这确实有效,但是如何处理参数是否太长。在这种情况下,我可以传递
$this->redirect(数组('action'=>'index','search','conditions'=>$conditions))代码>。如果不是一个小数据而是一个大数据怎么办?你能解释一下这里的逻辑吗?您是否有一个包含表单的搜索视图,该表单将发布到此搜索操作,并且您希望结果显示在索引上?实际上,这是我朋友的项目。元素
文件夹中有一个search\u worker.ctp
,谁有一个名为Search
的表单被发布到此搜索操作。在index.ctp
中有echo$this->element('Search_worker')代码>。我想她想在索引上显示结果,所以我重定向到index.ctp
并显示它。我只是不知道如何将数据传递到index.ctp
,我现在知道了,无论如何,谢谢。