Pages

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() {
        $this->Members->memberinfo();
    }
}
---

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

:D

 

1 comment:

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

    ReplyDelete

Any Questions or Suggestions ?