CodeIgniter Forums

Full Version: Where should this config array go?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]w1ntermut3[/eluser]
This is more of an academic question than anything, but anyhow: I've got an array of... stuff... page names, common fields, stuff like that... that's used by several controllers. The best place I can find to stick it is in MY_Controller, but having a config array in there seems... wrong. Maybe it's not, or maybe there's a better approach. Any suggestions?

El Forum

[eluser]capypara[/eluser]
Why not have another php file that includes that array (and any other code that you might want to reuse for your controllers) and include that php file in your controllers?

El Forum

[eluser]w1ntermut3[/eluser]
Could do. Is that the best way to do it? Where would I put that file? In an "includes" directory off my site root? How should it be named? Should it follow a particular structure?

Let me put it another way: if I was to give this project to YOU, where would you want to find a big array of global config-type stuff in order not to think "WTF?" Smile

El Forum

[eluser]InsiteFX[/eluser]
If you name your array:
Code:
$config['key'] = 'value';

// then load it or add it to the ./application/config/autoload.php
$this->config->load('filename');

// to access values
$value = $this->config->item('item name');

CodeIgniter User Guide - Config Class

El Forum

[eluser]w1ntermut3[/eluser]
Ok, thanks. That makes sense.

One - final, I promise - question: does config get loaded before routes? If I set my config array to be loaded using $this->config->load() - and add it to the autoload array - could I loop through it in /application/config/routes.php, setting up routing entries?