Welcome Guest, Not a member yet? Register   Sign In
How to get Config Items in Constants.php
#1

in CI 2.x i use the below code in the constants.php
Code:
$config = & get_config();
define('Fav', '<link href="' . $config['base_url'] . 'assets/images/favicon.ico" rel="shortcut icon" type="image/vnd.microsoft.icon" />');

and after i upgraded to CI 3.x it gives the below error :
Code:
Fatal error: Call to undefined function get_config() in

Somebody kindly help me of how to use config items in constants.php in Codeigniter 3.0.2

Thank you in advance
Reply
#2

Since Common.php (which defines get_config()) is loaded after the constants, you can't do this without modifying CI's core files.

My best recommendation to work around this would be to put these definitions in a separate config file (for example, /application/config/app_constants.php), then add that file to the list in $autoload['config'] in /application/config/autoload.php.

If you need the constants defined earlier (before the CI_Controller's constructor is executed), you may need to manually load the new config file from a hook or another file (maybe even /application/config/config.php, though I would generally advise against calling a function or including another file from within a config file, if it's possible to avoid doing so).
Reply
#3

(10-27-2015, 10:06 AM)mwhitney Wrote: Since Common.php (which defines get_config()) is loaded after the constants, you can't do this without modifying CI's core files.

My best recommendation to work around this would be to put these definitions in a separate config file (for example, /application/config/app_constants.php), then add that file to the list in $autoload['config'] in /application/config/autoload.php.

If you need the constants defined earlier (before the CI_Controller's constructor is executed), you may need to manually load the new config file from a hook or another file (maybe even /application/config/config.php, though I would generally advise against calling a function or including another file from within a config file, if it's possible to avoid doing so).

Thank you! Now i got the idea.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB