Clone wiki

Gen Options / Home


Gen Options is a CodeIgniter library that helps you to store your scripts' settings in database and allow you to access them easyly

How To Use IT

To call the library simply use this:

// Calling within a controller.

Or you can modify the config/autoload.php to autoload this library.

The library, automaticly getting the option items which is autoload values 'yes' from database. To get the option item, simply use this syntax:

// Calling site_title option from database. (this is a autoloaded item which is definited in database)
echo $this->gen_options->site_title;

As simply as this. If there isn't a item with given name, it will return NULL value.

As default, Gen Options does not checks database if given option name does not called. I did not added this. There could be some massieve queries. To call the option from database use get() method. This method does not returns anything back. If you want to enable database checking, you can enable it from application/config/gen_options.php.


// Multiple:
$this->gen_options->get('option1', 'option2', 'option3');

Updating option item

To modify existing option simply declare a variable in options class:

// Updating site_title option:
$this->gen_options->site_title = "My New Site";

Creating new option item

Creating new option item as simply as declaring a new variable:

// Creating new option with value:
$this->gen_options->site_url = "";

There is no need for serializing arrays. The Gen Options automaticly serializes arrays. Also Gen Options writes the boolean values as 1 or 0 to the database.

// The Gen Options automaticly serializes it.
$this->gen_options->main_pages = array('Home', 'Blog', 'Works', 'Contact');

// declaring boolean.
$this->gen_options->site_enabled = TRUE;

With set() method you can create/update multiple option items.

// Setting single option
$this->gen_options->set('option1', 'New value');

// Setting multiple options
	'site_title' => 'My New Title',
	'site_logo' => 'logo.png',
	'favicon' => 'favicon.ico',
	'header_banner' => 'banner.gif'

For making options autoload simply use makeAutoload() method. You can disable autoload with removeAutoload() method

// Making site_url autoload
// Multiple:
$this->gen_options->makeAutoload('option1', 'option2', 'option3');

// Disabling autoload for certain option.
// Multiple:
$this->gen_options->removeAutoload('site_title', 'other_option', 'another_option');

Removing option item

You can use unset() global function or, remove() method for removing items

// Removing option from database:
// Or:
// Multiple:
$this->gen_options->remove('site_title', 'site_url');

Method Chaining

All methods are chainable:

	->set('option1', 'value')

I hope you like it. If you have any problems, you can open an issue and I will try to fix it out.