user3733648
user3733648

Reputation: 1333

making variables accessable to all classes

I have a variable like

$shop_id = Configure::read('Settings.SHOP_ID');

which I want to make available to all the Controllers, which are extended from AppController.

What will be the best way to do so?

Upvotes: 0

Views: 41

Answers (1)

SaidbakR
SaidbakR

Reputation: 13534

Just define it in the app/Controller/AppController.php inside beforFilter callback as follows:

function beforeFilter(){
  public var $shop_id = '';
  parent::beforeFilter();
  $this->shop_id = Configure::read('Settings.SHOP_ID');
}

So in any of your controller's actions it will be accessible as $this->shop_id

Upvotes: 1

Related Questions