Geoff Garbers

Husband. Programmer. Tinkerer.

Bootstrapping plugin configuration in CakePHP 2

Feb 08, 2012

A new feature in CakePHP 2 is the ability to selectively enable and disable plugins in your APP/Config/bootstrap.php file. Plugins are no longer enabled by default in CakePHP 2 - you have to specifically enable them. However, with this functionality comes the ability to load up plugin bootstrap and routing configuration files.

However, something to keep in mind is that this bootstrap configuration file functions in the exact same way as your APP/Config/bootstrap.php file - that is, $config variables are not automatically loaded up.

Well, duh!

Seems pretty obvious, right? Well, that’s what I thought. I knew the function of the bootstrap file all along, but still somehow expected it do something different. It was such a stupid duh! moment that I thought it warranted a blog post pointing it out :)

Okay, so how do I mimic  the core.php configuration file?

So, how would you automatically load up the configuration? There are two methods to do this:

  • You could call Configure::load('PluginName.configFileName') from your bootstrap configuration, or
  • You can simply call Configure::write('configName', $configValue) directly from the bootstrap file.