How to import a controller in CakePHP


Suppose we have a controller named pages_controller.php, in which there is a function named index().

Now we are working in an another controller named users_controller.php, and we want to use the index function defined in Pages Controller.

App::import('Controller', 'Pages');
class UsersController extends AppController {
var $Pages;
function beforeFilter() {
$this->Pages =& new PagesController; /*Loads the class*/
$this->Pages->constructClasses(); /*Loads the model associations, components, etc. of the Pages controller*/
function index() {
This entry was posted in CakePHP, PHP and tagged , . Bookmark the permalink.

2 Responses to How to import a controller in CakePHP

  1. Andres Garcia says:

    Thanks!! it works perfectly!

  2. Hello, i’m coding on cakephp and now i want to import a controller to a Shell. Can you show me how to do this? Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *