Short answer
Yes, you can move data that came into Controller-A over to Controller-B, but in CodeIgniter the “clean” way is usually NOT to make one controller POST to another.
Instead you:
- Put whatever common logic you need into a model / library and call that from both controllers, or
- Redirect (or forward) the request to the second controller while storing the data somewhere the second controller can read (URL, session, flashdata, HMVC, cURL, …).
Below are the most common patterns, when to use them, and small code samples.
- Share a Model / Library (Recommended)
Use when: Both controllers just need to run the same PHP code (database insert, calculation, API call, …).
// application/models/Order_model.php
class Order_model extends CI_Model {
public function create($data)
{
return $this->db->insert('orders', $data);
}
}
/* ---- ControllerA.php ---- */
class ControllerA extends CI_Controller {
public function place_order()
{
$data = $this->input->post();
$this->load->model('Order_model');
$this->Order_model->create($data);
redirect('ControllerB/order_success');
}
}
/* ---- ControllerB.php ---- */
class ControllerB extends CI_Controller {
public function order_success()
{
$this->load->view('order_success_view');
}
}
Nothing ever has to be “posted” between controllers—both of them simply call the same model.
- Redirect + Flashdata
Use when: You want the browser to hit Controller-B next, and you only need the data once.
class ControllerA extends CI_Controller {
public function save()
{
$data = $this->input->post();
// keep it only for the next request
$this->session->set_flashdata('form_data', $data);
redirect('ControllerB/preview');
}
}
class ControllerB extends CI_Controller {
public function preview()
{
$data = $this->session->flashdata('form_data');
if (empty($data)) show_error('No data available');
$this->load->view('preview_view', $data);
}
}
Flashdata survives exactly one redirect, then disappears.
- Redirect + Query-String / URI-Segment
Use when: Data is small, non-sensitive, and can sit in the URL (e.g., an ID or a flag).
redirect('ControllerB/details/'.$order_id); // URI segment
// or
redirect('ControllerB/search?q='.urlencode($keyword)); // query-string
- “Internal” HMVC Call (Modules::run)
If you are running Modular Extensions HMVC (a popular add-on), you can call another controller method like a function and pass variables directly:
$data = ['id' => 123, 'qty' => 2];
echo Modules::run('ControllerB/mini_cart', $data);
That never leaves PHP, so there’s no real HTTP post—just a local method call handled by the HMVC loader.
- Instantiate the second controller manually
Possible but rarely advised. You would require_once() the other controller file, create an object, then call its method. It bypasses a lot of CI internals (hooks, routing, etc.), so most developers avoid it.
- cURL / HTTP Client
You could also fire a real HTTP POST via cURL/Guzzle to http://yoursite.com/controllerB/method, but that costs another HTTP request and is only justified if Controller-B is really acting like an external API.
Key Take-aways
• A controller’s job is to receive HTTP requests, not to act as one.
• Put shared business logic in models/libraries.
• When you truly need Controller-B to take over, use redirect + session/URL or an HMVC call.
That keeps your CodeIgniter 3 app simple, testable, and in line with MVC best practices.