Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter: Send whole POST request to method of another controller

I have a general controller which will get the POST request and decide to call known method of any controller. The controller will be chosen according to request.

Also I need to send whole POST request to chosen method without tampering.


More Description
Getting post request in controller 1, handling the request and decide to call known_method() of controller X | X != 1. Also sending primary request to the method. E.g.

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}");
}  

But because sending $post as parameter as it will send as GET request, may tamper it's data, it's not practical way. Also storing in session and retrieve that in target method is not a good solution.


Question: How I can send this data to my selected target?

Thanks in advance

like image 501
Hossein Shahsahebi Avatar asked Sep 27 '22 00:09

Hossein Shahsahebi


1 Answers

well you can just include the controller inside a controller

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();
}
like image 110
Daniel Krom Avatar answered Nov 15 '22 03:11

Daniel Krom