Welcome Guest, Not a member yet? Register   Sign In
Autoload a model and run a function?
#11

[eluser]chefnelone[/eluser]
I'm already trying with hooks using post_controller_constructoras the Hook Point.

But I get this message:

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: GetData_Hooks::$db

Filename: hooks/getData_hooks.php

Line Number: 14

and line 14 is a simple query:
Code:
$query = $this->db->query("SELECT * FROM texts");



It seems, to me, that the database library is not loaded at the time the hook is executed?
Should I use a differebt Hook Point than post_controller_constructor?

Maybe using MY_Controller is a better idea, but I'd like to learn how to use hooks as well.
#12

[eluser]rogierb[/eluser]
A hook is not a part of the CI superobject, just like a library is not.
So you have to use get_instance() to get the object.

Code:
$CI = get_instance();
$CI-db->query("SELECT * FROM texts");
#13

[eluser]chefnelone[/eluser]
[quote author="rogierb" date="1264096618"]A hook is not a part of the CI superobject, just like a library is not.
So you have to use get_instance() to get the object.

Code:
$CI = get_instance();
$CI-db->query("SELECT * FROM texts");
[/quote]

It works!
Thanks




Theme © iAndrew 2016 - Forum software by © MyBB