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

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?

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?

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

If you name your array:
$config['key'] = 'value';

// then load it or add it to the ./application/config/autoload.php

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

CodeIgniter User Guide - Config Class

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