views:

105

answers:

3

So I'm using CodeIgniter to build a website and I've made it so that all my specific settings are stored in a config file that's automatically loaded. I've also built a page that loads the settings file, makes a nice little table and allows me to edit everything from that page, afterwards it saves the entire page again (I know I could've done the same with a database but I want to try it this way).

My problem is that I can't seem to use this bit when autoloading of my config file is enabled, but when I disable autoloading I can't seem to manually load it, it never finds my variables. So what I'm doing here is just taking all values from the config file and putting them in a single array so I can pass this array onto my settings administration page (edit/show all settings).

$this->config->load('site_settings', TRUE);
$data['settings'] = $this->config->item('site_settings');
...
$this->load->view('template', $data);

config/site_settings.php

 <?php
    if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    $config['header_img'] = './img/header/';
    $config['copyright_text'] = 'Copyright Instituto Kabu';
    $config['copyright_font'] = './system/fonts/motoroil.ttf';
    $config['copyright_font_color'] = 'ffffff';
    $config['copyright_font_size'] = '32';
A: 

Is the file content definitely correct? (Check braces, quotes...)

IS the config file name the same as the one you're requesting?

Kurucu
A: 

Aren't you are trying to fetch an item that does not exist, so it just returns FALSE (boolean)? You are trying to load the item "site_settings", but you have no item with this name in the array index. Instead it should be, for example when loading a single item, $this->config->item('header_img');

Also with your 2nd parameter when loading it, each config file will be stored in an array index corresponding to the name of the config file.

$this->config['site_settings'].

Read more about the config class and it's usage here

rkj
From that same page 'If you are using the second parameter of the $this->config->load function in order to assign your config items to a specific index you can retrieve it by specifying the index name in the second parameter of the $this->config->item() function'Example:$this->config->load('blog_settings', TRUE);$blog_config = $this->config->item('blog_settings');$site_name = $blog_config['site_name'];Which is exactly what I want to do, put it in an array (here they use the array $blog_config[]), and this works for me but only if I disable autoload on my config page.
Fverswijver
A: 

Ok, I've found the solution. The problem was this check built into the Config library:

if (in_array($file, $this->is_loaded, TRUE))
{
    return TRUE;
}

So I edited it with an extra parameter to look like this:

function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE, $skip_loadedCheck = FALSE)
    {
        ...

                if(!$skip_loadedCheck) {
                    if (in_array($file, $this->is_loaded, TRUE))
                    {
                            return TRUE;
                    }
                }

Now, to load all the data in an array I can just do this:

$this->config->load('site_settings', TRUE, FALSE, TRUE);
$data['settings'] = $this->config->item('site_settings');
Fverswijver