Welcome Guest, Not a member yet? Register   Sign In
ControllerA calls method from ControllerB

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.

class ControllerB extends Controller {
   public function methodB() {
      $_SESSION['sessionB'] = 'i am set';

JS can call it through AJAX:

   new Ajax.Request(

But it's also useful in PHP land for controllerA to call controllerB/methodB:

class ControllerA extends Controller {
   public function methodA() {
      //psuedocode which I don't know how to do:

[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)

Theme © iAndrew 2016 - Forum software by © MyBB