Welcome Guest, Not a member yet? Register   Sign In
Loading a Model inside of a config file to pull configurations from DB and store in $config array

I'm refitting an existing website to work with codeigniter. The current system stores the navigation config in a single table cell using XML in this format:

        <name>Some Page</name>

I'm not sure what the original developer had in mind, but for reasons which will remain unexplained I would like to maintain this format for now.

I created a navigation model which pulls this XML from the db and converts it into an array.

&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    class Navigation_model extends CI_Model
     function __construct()
     function get_navigation()
      $this->db->join('style','style.styleID = pages.styleID','left');
      $navigation_query = $this->db->get();
      $navigation_row = $navigation_query->row_array();
      return xml2array($navigation_row['block']);
    /* End of file navigation_model.php */
    /* Location: ./application/model/navigation_model.php */

What I'm trying to do, is to load this model in a config file called navigation.php and load the navigation array into the global $config array. I tried both autoloading the model and loading inside navigation.php but to no avail.

&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    /* End of file navigation.php */
    /* Location: ./application/config/navigation.php */

I keep getting the following error:

Quote:Severity: Notice

Message: Undefined property: CI_Config::$load

Filename: config/navigation.php

Line Number: 3

How can I best accomplish what I am trying to do?

//this won't work in a config file.
//config files are manly for vars/arrays/constants.....


can't you use MY_Controller and extend your controllers to it, then place
model load and nav stuff there in a function that you can load in the MY_Controller class construct
will help load other custom common stuff.....


In the CI bootstrap, the configs are loaded way before the database (which isn't even required), so no models are available to the config. You can get around that by saving your xml files to the filesystem instead of the db, or use a MY_Controller as @weboap suggested.

Theme © iAndrew 2016 - Forum software by © MyBB