Downloads

Google Ad

CakePHP Configuration Plugin

Date: Sun, Oct 11th 2009, 17:38 Author: nick Views: 25464 Comments share

CakePHP Configuration Plugin

Info:
Watch:
Get it:
  • Download Now
  • git clone git://github.com/webtechnick/CakePHP-Configuration-Plugin
Configuration Plugin Version: 1.1
Author: Nick Baker
Email: nick@webtechnick.com
Website: http://www.webtechnick.com
Updates: http://www.webtechnick.com/blogs/view/223/CakePHP_Configuration_Plugin

SVN: svn co http://svn.xp-dev.com/svn/configuration-plugin configuration
BROWSE: http://projects.webtechnick.com/configuration
DOWNLOAD: http://projects.webtechnick.com/configuration.tar.gz


The Configuration plugin is an extremely useful way to store and read site-wide configuration via a database. The configuration plugin stores your configuration into your database and is made available throughout your site (views, controllers, models, tasks, etc...) using the standard Configure Class (http://book.cakephp.org/view/42/The-Configuration-Class).


Install

1) Copy the /configuration folder into /app/plugins/ 2) run
  1. cake schema run -path /plugins/configuration/config/sql -name config
in a terminal to build your database.


Setup

1) Open up your app_controller.php file and add:

  1. var $uses = array('Configuration.Configuration');
and add $this->Configuration->load(); into your beforeFilter().
  1. function beforeFilter(){
  2.   //Load Configurations
  3.   $this->Configuration->load($prefix); //$prefix is 'CFG' by default
  4. }
2) Navigate to http://www.yoursite.com/admin/configuration/configurations
3) Start adding configurations.


Usage

Whatever name/value pair you save in your configuration database, you'll have access to anywhere in your site via

  1. Configure::read('[prefix].[name]'); //returns 'value';


Example


Say I have a configuration table like so:

ID__|_NAME__|_VALUE
1    | email           | nick@webtechnick.com
2    | name           | Nick Baker


I could access this data anywhere in my app by simply using
  1. Configure::read([prefix].[name]);
(Default prefix is 'CFG', but you can change it in your app_controller.php).

In a view:
  1. $html->link('Email ' . Configure::read('CFG.name'), 'mailto:' . Configure::read('CFG.email'));

In a controller:
  1. $this->Email->from = Configure::read('CFG.email');

In a model:
  1. $this->findByEmail(Configure::read('CFG.email'));


You can get your entire Configuration table by not giving a name:
  1. debug(Configure::read('CFG')); //associative array.
  2. /*
  3. array(
  4.   'name' => 'Nick Baker',
  5.   'email' => 'nick@webtechnick.com'
  6. );
  7. */

As always, if you like the plugin, find a bug, or have a feature request please post a comment. =)

If you really like the plugin, please help support it by donating. Thanks!

I hope you find it useful,
Nick