![]() |
Loading a Model inside of a config file to pull configurations from DB and store in $config array - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Loading a Model inside of a config file to pull configurations from DB and store in $config array (/showthread.php?tid=51605) |
Loading a Model inside of a config file to pull configurations from DB and store in $config array - El Forum - 05-10-2012 [eluser]Unknown[/eluser] 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: Code: <NAVIGATION> 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. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 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. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); I keep getting the following error: Quote:Severity: Notice How can I best accomplish what I am trying to do? Loading a Model inside of a config file to pull configurations from DB and store in $config array - El Forum - 05-10-2012 [eluser]weboap[/eluser] Code: //this won't work in a config file. 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..... Loading a Model inside of a config file to pull configurations from DB and store in $config array - El Forum - 05-10-2012 [eluser]CroNiX[/eluser] 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. |