如何为两个不同的控制器调用一个视图,并根据codeigniter中的控制器重定向它们

时间:2014-11-01 03:09:51

标签: php codeigniter

我想根据控制器明智地重定向表单提交

    function list_mapdemand($id)
{
    $data['titlte'] = "mapdemand";
    $data['demand_id']  = $id;  
    $data['get_map_demand'] =   $this->demands_model->get_exist_demand_map_from_prospect($id);
    //print_r($data['get_map_demand']);
    //exit;
    //print_r($data['get_map_candidate']);
    $data['get_mapped_demand'] =    $this->demands_model->get_exist_prospective_candidate($id);
    $data['demand_results'] =  $this->demands_model->get_demand_details($id); 
    $data['candidates'] = $this->demands_model->get_candidates($id, $data['get_map_demand']);
    //print_r($data['candidates'])  ;
    $this->load->view("list_map_demand_to_candidate",$data);
}


 function list_search_mapdemand($id)
{
    $data['titlte'] = "mapdemand";
    $data['demand_id']  = $id;  
    $data['get_map_demand'] =   $this->demands_model->get_exist_demand_map_from_prospect($id);
    //print_r($data['get_map_demand']);
    //print_r($data['get_map_candidate']);
    $data['get_mapped_demand'] =    $this->demands_model->get_exist_prospective_candidate($id);
    $data['demand_results'] =  $this->demands_model->get_demand_details($id); 
    $data['candidates'] = $this->demands_model->get_candidates($id, $data['get_map_demand']);
    //print_r($data['candidates'])  ;
    $this->load->view("list_map_demand_to_candidate",$data);
}

一个控制器将用于搜索列表,另一个控制器用于普通列表。我必须按照控制器方式重定向页面,但必须控制一个视图页面。对于ADD,EDIT,VIEW。添加后必须转到上面提到的控制器。

2 个答案:

答案 0 :(得分:1)

可以做一些像<form action="<?php echo $action;?>"这样的事情,比如下面的控制器。

public function edit() {
// plus form validation or what ever you want
$this->getForm();
}

public function add() {
 // plus form validation or what ever you want
 $this->getForm();
}

public function getForm() {

// Make sure your uri segment correct uri segment 4 for me is id.

// http://localhost/codeigniter/project/admin/website/edit/54

// http://localhost/codeigniter/project/admin/website/add

  if ($this->uri->segment(4) === FALSE) {
    $data['action'] = site_url('admin/website/add');
  } else {
    $data['action'] = site_url('admin/website/edit/' . $this->uri->segment(4));
  }

  return $this->load->view(folder/file, $data);
}

答案 1 :(得分:0)

将此添加到您的功能中。比如你的list_mapdemand函数

$data['link']="YOUR_SUBMIT_LINK_FROM_list_mapdemand_FUNTION";  

并在list_search_mapdemand函数中添加

$data['link']="YOUR_SUBMIT_LINK_FROM_list_search_mapdemand_FUNTION";  

现在在标记

的视图中使用$ link
<from ... action="<?php echo $link; ?>....>