CakePHP – Import a Controller using App::import()

Hi All,

Have you ever use controller inside another controller(two controllers) in CakePHP ? If you are looking for the same thing, you are at the right place. I was working with CakePHP and i need to use a member info method of member controller in order controller(two controller in CakePHP). Instead of writing a code again in order controller, i searched for using controller inside controller. This can be easily done using App::import method of CakePHP.

App::import('Controller', 'Members');
class OrdersController extends AppController {
    var $Members;
    function beforeFilter() {
        $this->Members =& new MembersController; // Loads the class
        $this->Members->constructClasses(); // Loads the model associations, components, etc. of the Members controller
    }
    function index() {
        $this->Members->memberinfo();
    }
}

 


							
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: