CakePHP: Calling function from other controller


Import Controller of the function you want to use.

Once you imported  the controller you can call any function of this controller.

<?php
  //Import controller
  App::import('Controller', 'SmsOutgoings');

  class ReportsController extends AppController {
    
    public function add() {

         $message = "Notification: New report submitted!";

 

       //Instantiation
        $SmsOutgoings= new SmsOutgoingsController;
      //Call a method from SmsOutgoingsControllerwith parameter
      $SmsOutgoings->notify_user($user_id, $message); 
    }
  }
?>
 
 Other way is by using the requestAction() function

<?php
class ReportsController extends AppController {
    
    public function add() {

         $message = "Notification: New report submitted!";

 
      //Call a method from SmsOutgoingsController with parameter
      $this->requestAction('/sms_outgoings/notify_user', array($user_id, $message)); 
    }
  }
?>
  
 
Post a Comment

Popular posts from this blog

CakeAdminLTE is based on AdminLTE Theme for CakePHP 2.4+

CakePHP: COUNT data and GROUP BY date