What is the best way to create global variables in CakePHP?

ryonlife picture ryonlife · Mar 12, 2009 · Viewed 43.5k times · Source

I'd like to create a global variable in CakePHP. If I define something in in my app_controller.php like

var $varName

I can access

$this->varName

from any of my controllers, but I cannot get to it from models.

How can I create a global variable accessible from the models?

The value of $varName isn't known until runtime, so I don't think bootstrap.php is an option.

Answer

ax. picture ax. · Mar 12, 2009

CakePHP’s new Configure class can be used to store and retrieve application or runtime specific values. Be careful, this class allows you to store anything in it, then use it in any other part of your code