Welcome Guest, Not a member yet? Register   Sign In
Where should this config array go?
#1

[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?
#2

[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?
#3

[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
#4

[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
#5

[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?




Theme © iAndrew 2016 - Forum software by © MyBB