Skip to content

Instantly share code, notes, and snippets.

@peterfox
Last active December 18, 2015 15:39
Show Gist options
  • Save peterfox/5806381 to your computer and use it in GitHub Desktop.
Save peterfox/5806381 to your computer and use it in GitHub Desktop.
An example of a library that uses config groups inside a CodeIgniter config file
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
*defining a config with groups should look like
*
* $config['default']['hostname'] = '127.0.0.1'
* $config['default']['port'] = '1234'
*
*the constructor should then be able to load it by either taking a group name 'default' always being the option without
*a parameter, or just to take an array and use it as the expected array
*/
class CI_Something
{
public function __construct($config = 'default')
{
$expected = array('arguement1', 'arguement2', 'arguement3')
get_instance()->load->helper('array');
if(is_string($config))
{
get_instance()->load->config('something');
$config = elements($expected, get_instance()->config->item($config, 'something');
}
else
{
$config = elements($expected, $config);
}
//do what you need with your config parameters
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment