CakePHP: Calling function from other controller

Easily deploy an SSD cloud server on @DigitalOcean in 55 seconds. Sign up using this link and receive $100 in cloud credits: https://m.do.co/t/335732d1df0b



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)); 
    }
  }
?>
  
 

Comments

Popular posts from this blog

CakePHP 4: Firebase Cloud Messaging Component in CakePHP for Push Notification

CakePHP 4 : Using Component inside Command ( Shell )

LIMIT SSH ACCESS BY COUNTRY