Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP 2.3.8: Calling Another Controller function in CronController.php

For CakePHP 2.3.8 How can I call Another Controller function in CronController.php

Any ideas?

like image 992
Aditya P Bhatt Avatar asked Oct 13 '13 12:10

Aditya P Bhatt


2 Answers

Below is the code:

App::import('Controller', 'Products'); // mention at top

// Instantiation // mention within cron function
$Products = new ProductsController;
// Call a method from
$Products->ControllerFunction();

Hope it helps some one !

like image 106
Aditya P Bhatt Avatar answered Oct 11 '22 23:10

Aditya P Bhatt


I referenced the manual to find a solution to this.

public function that_controller_function_you_are_writing () {

    # this is cakes way of running required
    App::import('Controller', 'Users');
    $UsersController = new UsersController;

    # now you can reference your controller like any other PHP class
    $UsersController->that_function_you_needed();
}

This is the link: http://book.cakephp.org/2.0/en/core-utility-libraries/app.html

like image 29
usumoio Avatar answered Oct 11 '22 22:10

usumoio