[eluser]Phil Sturgeon[/eluser]
[quote author="young" date="1233909426"]
So, if the controller is backoffice (the management system of website), do something.[/quote]
thanks for your apply, i think it should be used after "post_controller_constructor", because CI hadn't instantiated before that.
then if i want to use hook in pre_controller, how can i load helper functions?
for example, i want to redirect the url in pre_controller[/quote]
You need to remember that anything you do in pre_controller is going to be a hack. Only certain parts of the CI framework are loaded, and this instance itself has not really got going.
It is possible to include a helper simply by using include_once(APPPATH.'helpers/text_helper.'.EXT); but other than that you don't have any access to load them.
The problem is that any model, library or helper that tires to access the instance before it is created, will screw up. url_helper is one of these, as most of the functions call site_url() which calls the instance to get the config class.
You would need to make a MY_url_helper.php and override site_url() with this function.
Code:
if ( ! function_exists('site_url'))
{
function site_url($uri = '')
{
$config =& load_class('Config');
return $config->site_url($uri);
}
}
That will stop it from accessing the entire instance, so you can use the url helper to get redirect.
That's just a theory. Let me know if you would like a few more examples of code, will knock something together and test it.
Would do it now, but just moved my VPS and I have 7 broken live sites right now...!