cakephp plugin configuration

David Jones
@david3jones
avatar-davidejones

Recently i began to develop a shopping cart plugin that will do the basics adding/deleting/updating etc. With the options to checkout to various different payment providers. The purpose of this was to have something resusable that i can use for any ecommerce project and just expand on it if needed.

Anyway whilst diving into the plugin side of cakephp i struggled to find much information on configuration files. I’ve seen a couple of methods on the net and thought i would share them with you.

Method 1

This basically involves create a config file in the plugins folder. So say your plugin is called test it would appear like this /app/plugins/test/config/test_settings.php and would look something like this inside the file

class TestSettings {
    	var $defaults = array(
    		'variable1' => 'test',
    		'variable2' => 'test'
    	);
}

and then you would import it into your plugin class using the following

App::import('Config', 'Test.test_settings');

Method 2

The second method is to create a bootstrap file in your plugin folder like this /app/plugins/test/bootstrap.php

Then in order to load your plugins bootstrap files you can add something to the main app bootstrap file:

$Folder =& new Folder(APP.'plugins');
$plugins = $Folder->ls(); // for better performance - make sure you cache it somewhere
//foreach($plugins as $plugin)
foreach($plugins[0] as $plugin)
{
    	// include bootstrap.php of all plugins
    	if(file_exists(APP.DS.'plugins'.DS.$plugin.DS.'bootstrap.php'))
    	{
    			require_once(APP.DS.'plugins'.DS.$plugin.DS.'bootstrap.php');
    	}
}

Comments

    Comments are currently closed