I'm writing my first basic bare bones MVC patterns setup in PHP. I know global variables are bad, and I aslo know I don't want all of my classes to have access to all of my config vars.
I have a settings.php file that I would like to define a bunch of constants in, like my db connection info, directory structure info, email addresses and so on. It will be one centralized location that holds all of my important information.
What's the best way to implement a config class so that each of my base classes for my controller and model only have access to the config vars they need? For example, my model base class should have access to by db connection info.
Basically I am just asking how anybody whole rolls their own MVC setup handles config information without declaring global variables, like we used to back in the procedural days.
Thanks.
You're going to get a bunch of answers on this as it basically boils down to preference.
Personally, ive used a config array. example:
$conf['db']['username'] = "username";
$conf['db']['password'] = "password";
Then just pass byref the pieces you need into where they need to go.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With