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

[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 {
   public function methodB() {
      session_start();
      $_SESSION['sessionB'] = 'i am set';
   }
}

JS can call it through AJAX:

Code:
[removed]
   new Ajax.Request(
      'index.php/controllerB/methodB'
   );
[removed]

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

Code:
class ControllerA extends Controller {
   public function methodA() {
      //psuedocode which I don't know how to do:
      $this->load->controller('controllerB');
      $this->controllerB->methodB();
   }
}


Messages In This Thread
ControllerA calls method from ControllerB - by El Forum - 01-21-2010, 04:39 PM
ControllerA calls method from ControllerB - by El Forum - 01-21-2010, 06:12 PM



Theme © iAndrew 2016 - Forum software by © MyBB