Search code examples
cakephpcomponentsrequesthandler

2 Components in 1 Controller


Hi I am really new in CakePhp, I hope you can help me

    class BookingsController extends AppController {

    public $helpers = array("PDF");
//public $virtualFields = array(
// 'full_name' => 'CONCAT(Customer.cust_fname, ", ", Customer.cust_fname)'
//);
    public $components = array('RequestHandler');

    public $components = array('Search.Prg');

    public $presetVars = array(
        array('field' => 'search', 'type' => 'value'),
    );
/**

My question now is that I need $components in both. Is there any way to merge it together? Or how can I call both request handler and search.prg? I hope u can help


Solution

  • Simply merge the arrays

    public $components = array('RequestHandler', 
                               'Search.Prg', 
                               'OtherComponent', 
                               'ExtraComponent' /*etc*/);
    

    Cake is smart enough to get what you mean. Also works for $helpers and $uses... and I guess pretty much everything really. You need to keep an eye on documentation, it says clearly how to do what you asked.