Variable Placement |
[eluser]CI_Newb[/eluser]
I've read arguments from both sides, but where do you keep your variables for your application? 1) All variables stored in a central file 2) Variables are created on the fly in the model/view/controller when needed. I'm talking common variables. Example Code: $cur_date = date ('Y-m-d');
[eluser]umefarooq[/eluser]
two ways you can keep variables one keep in config file and get values from config file, put that config file in application>config folder with your desired name here is user guide to get values from config files http://ellislab.com/codeigniter/user-gui...onfig.html other way as i can see these are just static data in variables you can create a parent class for controller like MY_controller and put these variables at class level and will available to all child controller after extending form this class read this article for parent class http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY
[eluser]CroNiX[/eluser]
Well, since you are talking about what could be considered as "global constants", I would put them in the /application/config/constants.php file. If they are controller specific, put them in their own config as umefarooq suggests.
[eluser]CI_Newb[/eluser]
these variables would need to be accessible for models, controllers and views. So if I'm understanding right, they should be put in the constants file so they can be accessed in any include, model, controller view etc ... |
Welcome Guest, Not a member yet? Register Sign In |