Codeigniter:将整个 POST 请求发送到另一个控制器的方法

Codeigniter: Send whole POST request to method of another controller

我有一个通用控制器,它将获取 POST 请求并决定调用任何控制器的已知方法。将根据要求选择控制器。

我还需要将整个 POST 请求发送到所选方法而不进行篡改。


更多说明
controller 1 中获取 post 请求,处理请求并决定调用 controller X | X != 1known_method()。还向该方法发送主要请求。例如。

public function index()
{
    $post = $this->input->post();

    //handling the request and decide to call the following method of another controller

    Controller_X->known_method($post);
    //OR
    redirect("site_url/controller_X/known_method/{$post}");
}  

但是因为发送 $post 作为参数,因为它将作为 GET 请求发送,可能会篡改它的数据,这不是实用的方法。同样存储在 session 中并在目标方法中检索它不是一个好的解决方案。


问题:如何将这些数据发送到我选择的目标?

提前致谢

好吧,您可以将控制器包含在控制器中

if(toIncludeController_a()){
      $this->load->library('../controllers/Controller_a');
      $this->controller_a->myFunction(); //<- this function can also get the post data using $this->input->post
}

contoller_a:

public function myFunction(){
     $data = $this->input->post();
}

建议,我认为会更干净:

1) 让请求在库中处理,而不是控制器。相应地调用库。

if(request1) {
    $this->load->library('lib1');
    $this->lib1->handle(); // in lib1, retrieve all post without tampering
} else if(request2) {
    ...and so on
}

2) 在客户端或js中处理决策请求

重定向将不起作用,因为数据会丢失或需要重新发布。

Update/comment: 库不是帮手或精简版,最好将其视为业务逻辑。操作或重逻辑通常放在这里,模型交互也是如此。