Welcome Guest, Not a member yet? Register   Sign In
Hooks - pre_controller vs. post_controller_constructor
#1

I got two hooks. "guardian" and "orm" both of them are now starting as "post_controller_constructor" beacuse I need db connection. 
But side effect is, that I can't use Orm and Guardian methods in controller constructor because they are not loaded yet. 
And it is very anoying to write the same code in to all controller methods because I can't use constructor to put it in.

I passed through by writing method postConstructor() which is called as first in controller method. And I put repeatly used code in it. 

But I don't like this sollution. 

Does enybody have an idea how to solve this better way?
Reply
#2

for db connection model, view and controller u can use $CI =& get_instance(); $CI->db->....
Reply
#3

If you're autoloading the DB library you should be able to use pre_controller.
Reply
#4

I tried but, after I attached hooks pre_controller, there was no DB connection available.
Im not exactly sure, but CI autoloads libraries before controller constructor BUT after hooks. This seem to be reason, why there is no DB connection available in hooks.
Reply
#5

(03-28-2017, 08:44 AM)Sezu Wrote: Im not exactly sure, but CI autoloads libraries before controller constructor BUT after hooks.

It loads them from inside the constructor.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB