Home

Welcome

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.
$this->load->library('gen_options');

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.

$this->gen_options->get('option1');

// 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 = "http://www.example.com/";

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
$this->gen_options->set(array(
	'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
$this->gen_options->makeAutoload('site_url');
// Multiple:
$this->gen_options->makeAutoload('option1', 'option2', 'option3');

// Disabling autoload for certain option.
$this->gen_options->removeAutoload('site_title');
// 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:
unset($this->gen_options->site_enabled);
// Or:
$this->gen_options->remove('site_enabled');
// Multiple:
$this->gen_options->remove('site_title', 'site_url');

Method Chaining

All methods are chainable:

$this->gen_options->get('option1')
	->set('option1', 'value')
	->remove('option2');

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

Updated

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.