hooks + database(not able to access 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: hooks + database(not able to access database) (/showthread.php?tid=5293) |
hooks + database(not able to access database) - El Forum - 01-15-2008 [eluser]nirbhab[/eluser] hello everybuddy, i have a small problem. i am not able to access database in hook. config.php Code: $config['enable_hooks'] = TRUE; hooks.php Code: $hook['pre_controller'] = array( getsystem.php Code: <?php wht to do? hooks + database(not able to access database) - El Forum - 01-16-2008 [eluser]ejangi[/eluser] You probably need to load the database stuff explicitly as the DB stuff normally gets loaded during the Controller (whereas you're doing this hook pre-controller): Code: <?php hooks + database(not able to access database) - El Forum - 01-16-2008 [eluser]nirbhab[/eluser] i did the following but it shows error in loading. Code: $this->CI->load->database(); means Code: class getSystem extends Controller is it right to perform, i can now use all my ci class by default. hooks + database(not able to access database) - El Forum - 01-16-2008 [eluser]tonanbarbarian[/eluser] umm there may be a syntax error in those examples the get_instance looks like it was meant to have a comment after it, but it is not commented correctly try this Code: <?php hooks + database(not able to access database) - El Forum - 01-16-2008 [eluser]nirbhab[/eluser] I pasted the above code: n guess wht Quote:A PHP Error was encounteredFatal error: Call to a member function database() on a non-object in D:\www\vhosts\localhost\hook\system\application\hooks\getsystem.php on line 10 one more thing to mention: i am auto loading database: autoload.php Code: $autoload['libraries'] = array('database'); hooks + database(not able to access database) - El Forum - 01-16-2008 [eluser]tonanbarbarian[/eluser] The problem is you are using a pre-controller hook. At that point the controller does not technically exist yet. try using a post_controller_constructor hook instead and it should work hooks + database(not able to access database) - El Forum - 01-16-2008 [eluser]nirbhab[/eluser] nice idea! thanx dear it worked well :-) |