![]() |
HMVC problem...CI spits out undefined property when loading database. - 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: HMVC problem...CI spits out undefined property when loading database. (/showthread.php?tid=25547) |
HMVC problem...CI spits out undefined property when loading database. - El Forum - 12-16-2009 [eluser]Jamongkad[/eluser] Hi all! My problem stems when I extend the Controller class. //MX_Controller.php before HMVC it was MY_Controller.php abstract class TemplateController extends Controller { //... } My controllers seem to work well with the current setup. Even right down to the my module controllers. The problem starts when I try to access the DB, CI complains that $db is an undefined property. And that's when I invoke $this->load->database()! Strangely when I revert back to using Controller it works fine. I feel like this is a simple problem to lick but for the moment I'm stumped... HMVC problem...CI spits out undefined property when loading database. - El Forum - 12-16-2009 [eluser]wiredesignz[/eluser] Your abstract class definition is not relevant to the problem, why are you showing this? The MX_Controller file is not actually required, you may save your controller base class in a like named application/libraries file and it will be (spl) autoloaded for you as needed. Please explain your problem in more detail and show some real code. Make sure you use the forums [code] ... [/code] tags properly. HMVC problem...CI spits out undefined property when loading database. - El Forum - 12-16-2009 [eluser]Jamongkad[/eluser] I apologize I should have been a bit more clear with my intention. I don't know if I should provide any code for such a trivial operation. In a nutshell I cannot access the database library when using my custom base controller. Even when I'm inheriting from HMVC's Controller class. HMVC problem...CI spits out undefined property when loading database. - El Forum - 12-16-2009 [eluser]wiredesignz[/eluser] I have created code that mimics the code example you give and accessing the database ($db object) works fine. HMVC problem...CI spits out undefined property when loading database. - El Forum - 12-16-2009 [eluser]Jamongkad[/eluser] Now I'm kicking myself in the arse for not having the foresight to give some actual code. When I think about it...my Templater library calls an instance of CI within it's constructor. Do you think it has something to do with the error? Code: abstract class TemplateController extends Controller { HMVC problem...CI spits out undefined property when loading database. - El Forum - 12-16-2009 [eluser]wiredesignz[/eluser] So where are you accessing the database? I can't see any reference to the $db object in your code. HMVC problem...CI spits out undefined property when loading database. - El Forum - 12-16-2009 [eluser]Jamongkad[/eluser] Ok here is the offending code...at this point is where CI cries foul saying that I'm calling on a member function get on a non object. I'm stumped...I switch back to inheriting from the Controller and it works fine. But as soon as I inherit back to TemplateController things go awry. Code: class Test extends TemplateController { |