Saturday, October 8, 2011

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() {

hope this post helped you.
let me know for Questions by commenting.
best luck.




1 comment:

  1. Nice help Wonder full Post bhavin !
    this post helped me Many thanks to Blogger 1


Any Questions or Suggestions ?


Professional & Experienced Freelance Developer From India, Technologist, Software Engineer, internet marketer and Open Sources Developer with experience in Finance, Telecoms and the Media. Contact Me for freelancing projects.

Enter your email address:

Delivered by FeedBurner

PHP Freelancer India - Google+