• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shutdown hooks and redirect()

First post here... hi everyone.

I've written some simple convenience functions in my parent controller to deal with groups of flashdata messages. I've been using the "post_controller" hook to save this collated data to the session before execution ends. However, I've found that this doesn't work when redirect() has been used, as redirect() halts execution, and therefore none of the hooks in the shutdown sequence get triggered.

At first I did some messing about to see if I could trigger the save in the controller's destructor. This won't work though as the database driver is a member of the controller itself, and so it's already been destroyed by the time the controller's own destructor is called.

So failing that, I've made an edit to the redirect() function, to call the hook I need manually:

if ( ! function_exists('redirect'))
function redirect($uri = '', $method = 'location', $http_response_code = 302)
  if ( ! preg_match('#^https?://#i', $uri))
   $uri = site_url($uri);

  global $EXT;

   case 'refresh' : header("Refresh:0;url=".$uri);
   default   : header("Location: ".$uri, TRUE, $http_response_code);

I'm not a fan of this approach though - it's pretty hacky, and obviously still doesn't guarantee that the other hooks are called.

Is there a better way?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.