How to pass variable from controller to all view files (.ctp) in cakephp

My controller: Controller/appController/OrdersController.php

I have a function named nocontact()

and I can pass the nocontact.ctp variable like this:

 $allNoContacts = $result;
        $service_charge=$this->ServiceCharge->find('all');

        $zero_service_charge=$this->ZeroServiceCharge->find('all');
        $zero_service_charge=$zero_service_charge[0]['ZeroServiceCharge']['items'];
        $this->set(compact('allNoContacts','service_charge','zero_service_charge')); 

      

How can I pass this variable to all view files in OrdersController?

+3


source to share


1 answer


You can set a variable in the beforeRender method of your OrdersController.



public function beforeRender() {
    $this->set('name', 'value');
}

      

+6


source







All Articles