ControllerA calls method from ControllerB - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: ControllerA calls method from ControllerB (/showthread.php?tid=26727) |
ControllerA calls method from ControllerB - El Forum - 01-21-2010 [eluser]tokyotech[/eluser] How do I get one controller to call a method from another controller? Is it considered bad practice if I have to resort to doing this? Let me explain why I need to do this. I have this ControllerB which has a methodB() which I'd like to use both from JS land and PHP land. Code: class ControllerB extends Controller { JS can call it through AJAX: Code: [removed] But it's also useful in PHP land for controllerA to call controllerB/methodB: Code: class ControllerA extends Controller { ControllerA calls method from ControllerB - El Forum - 01-21-2010 [eluser]Colin Williams[/eluser] That's just an architecture that doesn't make sense to me. Any bit of code that two controllers must execute should live in either a model, a library, or available in the parent class (Controller or MY_Controller) |