Reputation: 5464
How to run an function in config file ?
when i try this, i getting an error like this
Fatal error: Call to undefined function setting() in C:\wamp\www\urunsite\application\config\site.php on line 7
my config file
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
// default language
$config['lang'] = 'tr';
// Default user role id
$config['default_role'] = setting('company', 'name');
/* End of file site.php */
the setting() function is auto loading.
please help me.
Upvotes: 0
Views: 2537
Reputation: 770
setting()
isn't a valid function.. If it's your own custom function from a model file or elsewhere, you're not giving this config file proper access to that function.
You said that the setting()
function is autoloading, but how is it being autoloaded? Is it from a custom Library? Helper? Model? Depending on which it is, you would need to call the function with:
$this->library_name->setting('company', 'name');
or
$this->model_name->setting('company', 'name');
etc.
Upvotes: 0
Reputation: 102794
Config files are loaded early in execution, but you should have no problem running any functions there as long as they have been defined. If you need access to functions that aren't defined at config load time, you have no choice but to load the config file manually instead of automatically, or use a hook to load the needed resources. You will have to use the latter if you want to run helper functions in a core config file, custom config files are usually loaded on demand so it's a bit easier.
Upvotes: 2