I want to call a function in a controller (say controller_a) from another controller (say controller_b)
Please help me ..
I want to call a function in a controller (say controller_a) from another controller (say controller_b)
Please help me ..
Shared controller functions should usually be in an extended controller class:
<?php
/**
* File: /application/core/MY_Controller.php
*/
class MY_Controller extends CI_Controller {
/**
* Prefix with an underscore if you don't want it
* publicly available through URI-routing
*/
public function _some_shared_method()
{
// some common operation here
}
}
Then, make sure any controller that needs to use this function extends MY_Controller
.
You would be breaking MVC by calling a controller from another controller. Consider either using a helper, or library for the function you are trying to call.
When controllers call other controllers you're operating in an HMVC framework. See Modular Extensions
If you're looking for information on controller inheritance, I recommend reading Phil Sturgeon's post on Keeping It Dry
© 2022 - 2024 — McMap. All rights reserved.