Welcome Guest, Not a member yet? Register   Sign In
Same tasks in each controller: controller inheritance?
#2

[eluser]xwero[/eluser]
a hook is the most elegant solution in my book. You create/fetch an authentication library and you add a post_controller_constructor hook that uses the authentication library. It can be a function if you want
Code:
function access()
{
  $CI =& get_instance(); // this is the reason why it has to be a post_controller_constructor hook
  $CI->load->library('authentication'); // as a precaution if the library isn't defined in the autoload file
  if($CI->uri->segment(1) == 'admin' && /* I assume the admin has a own directory/controller */
     ! $CI->authentication->logged_in())
  {
     redirect(''); // url helper function
  }
}
I prefer the loose coupling of the hooks better than the extending of controllers.


Messages In This Thread
Same tasks in each controller: controller inheritance? - by El Forum - 10-10-2008, 05:57 AM
Same tasks in each controller: controller inheritance? - by El Forum - 10-10-2008, 06:16 AM
Same tasks in each controller: controller inheritance? - by El Forum - 10-10-2008, 06:40 AM
Same tasks in each controller: controller inheritance? - by El Forum - 10-10-2008, 06:45 AM
Same tasks in each controller: controller inheritance? - by El Forum - 10-10-2008, 06:48 AM
Same tasks in each controller: controller inheritance? - by El Forum - 10-10-2008, 09:24 AM
Same tasks in each controller: controller inheritance? - by El Forum - 10-10-2008, 09:41 AM
Same tasks in each controller: controller inheritance? - by El Forum - 10-10-2008, 09:54 AM
Same tasks in each controller: controller inheritance? - by El Forum - 10-11-2008, 01:26 AM
Same tasks in each controller: controller inheritance? - by El Forum - 10-11-2008, 03:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB