get_instance() undefined in custom librairies ? :( - 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: get_instance() undefined in custom librairies ? :( (/showthread.php?tid=20462) |
get_instance() undefined in custom librairies ? :( - El Forum - 07-10-2009 [eluser]doMynation[/eluser] Good day, Although I've seen many people pretending to do it without any error, I just can't access the CI core base using: Code: $CI =& get_instance(); It says the function is undefined. I need to load some CI ressources (helpers for example) within my library. Am I doing something wrong ? Even the user guide says it's the way to do it: http://ellislab.com/codeigniter/user-guide/general/creating_libraries.html Thank you ! get_instance() undefined in custom librairies ? :( - El Forum - 07-10-2009 [eluser]Michael Wales[/eluser] Where are you including the library from? get_instance() undefined in custom librairies ? :( - El Forum - 07-10-2009 [eluser]Colin Williams[/eluser] Are you using your library within the CI app? Show some code that reproduces the error. That's always a vital first step when you think you've spotted a bug. get_instance() undefined in custom librairies ? :( - El Forum - 07-10-2009 [eluser]doMynation[/eluser] Well I've tested two things. First, I've tried simply modifying the Exceptions library (which is autoloaded, at least I think). Then I extended it, and added it to autoload in autoload.php. get_instance() undefined in custom librairies ? :( - El Forum - 07-10-2009 [eluser]Michael Wales[/eluser] To extend a CodeIgniter library you should just make a file named MY_Exceptions.php in the libraries directory (this is configurable via config.php). get_instance() undefined in custom librairies ? :( - El Forum - 07-10-2009 [eluser]doMynation[/eluser] Yes that's what I've done, and I still can't access the get_instance function. Sounds like the library is loaded BEFORE the CI_BASE. get_instance() undefined in custom librairies ? :( - El Forum - 07-10-2009 [eluser]Colin Williams[/eluser] Yeah, the exceptions class is kind of the exception. You are limited to what you can do in there. get_instance() undefined in custom librairies ? :( - El Forum - 07-10-2009 [eluser]doMynation[/eluser] Awww I see... lol. Well then, I'm simply trying to perform a quick redirection to the default controller when a controller or controller function is not found. Is there an easy to achieve this ? (I'm using clean URLs) I've read multiple post where they extend the CI_Route or CI_Extensions with a considerable amount of code. Is there a kind of "shortcut" for this ? |