CakePHP Configuration Plugin
Please Support:
CakePHP Configuration Plugin
Info:
- Version: 1.1
- Requirements: CakePHP 1.x/2.x
- Article: CakePHP Configuration Plugin Discussion and Examples
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).
in a terminal to build your database.
and add $this->Configuration->load(); into your beforeFilter().
2) Navigate to http://www.yoursite.com/admin/configuration/configurations
3) Start adding configurations.
Say I have a configuration table like so:
I could access this data anywhere in my app by simply using (Default prefix is 'CFG', but you can change it in your app_controller.php).
In a view:
In a controller:
In a model:
You can get your entire Configuration table by not giving a name:
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
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- cake schema run -path /plugins/configuration/config/sql -name config
Setup
1) Open up your app_controller.php file and add:- function beforeFilter(){
- //Load Configurations
- $this->Configuration->load($prefix); //$prefix is 'CFG' by default
- }
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- 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
- Configure::read([prefix].[name]);
In a view:
In a controller:
- $this->Email->from = Configure::read('CFG.email');
In a model:
- $this->findByEmail(Configure::read('CFG.email'));
You can get your entire Configuration table by not giving a name:
- debug(Configure::read('CFG')); //associative array.
- /*
- array(
- 'name' => 'Nick Baker',
- 'email' => 'nick@webtechnick.com'
- );
- */
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