Welcome Guest, Not a member yet? Register   Sign In
Hooks and Hook points
#1

[eluser]cdmn[/eluser]
Hi.

ive did some research with hooks and hook points and of course ive some questions.
Maybe someone will be nice enough to answer them :-)

My hook does nothing special, just:

Code:
$CI =& get_instance();
var_dump($CI);

So.

Hook with pre_system point:
Code:
Fatal error: Call to undefined function: get_instance() in ...
Hook with pre_controller point:
var_dump returns NULL.

Other hook points returns an object, which you can work with.
So my question would be, what resourses i can use, at pre_system and pre_controller points? Of course ill need to load some libraries, should i use CI core functions like load_class? Looking for some explanation and advice :-)
#2

[eluser]deviant[/eluser]
You can only use get_instance once the Controller has been created as far as I know.
#3

[eluser]cdmn[/eluser]
Yes i understand that.
But whats the purpose of pre_system and pre_controller hook points?
Maybe some real application example?
#4

[eluser]Nillian[/eluser]
I recently used a pre-system hook to reformat 'bad' URLs. The old version of the site I'm rebuilding used query strings in the URI, whereas I'm now using CodeIgniter's friendly URLs. So, I wrote a little hook that begins before the routing system is loaded, which grabs the $_GET variable (if any) and validates the query string in the URI, then reformats it into the new friendly URLs and performs a Header("Location: [newurl]").

With this hook in place, all of the old links (on forums and peoples bookmarks etc) will still work when the new site goes live. I'm not sure if this is a good way of doing things, but it's a real world example of the pre_system hook for you Smile
#5

[eluser]cdmn[/eluser]
Sweet, got the idea :-)

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB