Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 variable to nocontact.ctp as follows:

 $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 under OrdersController?

like image 900
Abdus Sattar Bhuiyan Avatar asked Mar 15 '23 14:03

Abdus Sattar Bhuiyan


1 Answers

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

public function beforeRender() {
    $this->set('name', 'value');
}
like image 179
Narendra Vaghela Avatar answered Apr 25 '23 16:04

Narendra Vaghela