Last Updated: September 09, 2019
·
3.694K
· thatdiegokid

Dynamic Constants in Codeigniter 2.1.2

I wanted to define the settings as constants to be able to control them through a settings page.

Created a table in the DB to hold the constant name and value

in /application/config/constants.php I added this:

require_once( BASEPATH .'database/DB'. EXT );
$db =& DB();
$query = $db->get( 'settings' );
foreach( $query->result() as $row ){ define($row->title, $row->value); }