Welcome Guest, Not a member yet? Register   Sign In
Custom Constants File
#1

[eluser]jpschroeder[/eluser]
Hello,

I'm new to codeigniter (about a week), and very impressed with its easy of use and functionality (rails done right?).

However, I have a brief question I'm sure is simple to answer. I want to create a custom file containing constants pertinent to my application (calling the file definitions.php). How can I go about doing this and have it load automatically without editing the framework itself?

I thought the autoload.php "config" section would allow this but apparently it is for loading other kinds of configurations, not constants. (Gives me this error when I put in my own file: Your definitions.php file does not appear to contain a valid configuration array.)

Thanks in advance.
#2

[eluser]davidbehler[/eluser]
You can abuse the autoloading functionality to realise this.

Simply create a file called definition.php with all your constants and add this to the file:
Code:
$config = array();

If you now add 'definition' to the config autoload array, it should work.

Not tested but I guess that fixes the error you got.
#3

[eluser]jpschroeder[/eluser]
thanks waldmeister. I changed the code to reflect your suggestion and you're right the error goes away, and the constants are working fine...thank you

I'll use it for now, but does seem like a bit of a hack. I would be interested if there are any other preferred methods or if this really is a best-practice.




Theme © iAndrew 2016 - Forum software by © MyBB