Welcome Guest, Not a member yet? Register   Sign In
Problems loading database early in libraries? Workaround:
#1

[eluser]Mirage[/eluser]
Hi all,

Just wanted to reiterate here what I posted in the Bug Tracker along with a better workaround than patching the Loader class. For reference, this is the reported bug:

http://codeigniter.com/bug_tracker/bug/8134/

I have some classes which are autoloaded very early which use the database class. You would probably experience the same problem if you used an early hook in your application. Anyway, the libraries load a [configurable] database connection, with the return parameter.

Because it is returned, the loader does NOT assign it to the controller. As a result, subsequently loaded models will not be assigned the db property, because of the class check that the Model Loader does (see reported bug).

In the past, I just circumvented this by making a loader extension to override the model method and remove the check.

A less intrusive workaround is to autoload the database class before any of the libraries that need a database connection. It's not a fix by any means and the bug should still be addressed.

If you need to load named database connections, the autoloader won't do it. Another option then is to call $this->load->database('somegroup'); in the controller constructor.

This is one of those things that has been around forever. Hoping EllisLab will fix this...




Theme © iAndrew 2016 - Forum software by © MyBB