Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to call another controller function in a controller in cakephp

    • 0
    • 1
    • 1
    • 1
    • 3
    • 0
    • 0
    • 0
    • 8.31k
    Comment on it

    Hello reader's In this tutorial we will discuss about "How to call another controller function in a controller in cakephp".
    For doing this, first of all import controller function in your controller that function you want to call.
    Once you import the controller, crate an object of that controller than call the function through the created object(which have pointed the imported controller).
    Here is a demo.

    /*Author: Jaydeep Dhoundiyal* /
    
    <?php
    
      //Import controller
      App::import('Controller', 'Users');
    
      class ReportsController extends AppController {
    
        public function callFunction() {
            $user_id = 21;
            $message = "Hello every one!";
    
               //create an object
            $usersObj= new Users;
    
              //Call a function of Users controller with 2 parameters
              $usersObj->notify_user($user_id, $message); 
        }
      }
    ?>
    

 3 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: