I’m using HMVC in CodeIgniter https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home
How do I setup a controller that would automatically run when accessing a user-only page.
This is for the purpose of checking if a user is currently logged in or not. I’ve already made a helper to check if user is logged in:
<?php
if(!defined('BASEPATH')) exit('No direct script access allowed');
if (!function_exists('is_logged_in')){
function is_logged_in(){
$CI =& get_instance();
$logged_in = FALSE;
$user_data = $CI->session->userdata('logged_in');
if(!empty($user_data)){
$logged_in = TRUE;
}
return $logged_in;
}
}
But the only thing that I know is to call this method on the constructor of each controller on each of the modules. I would be repeating the same code on every controller just to check if the user is logged in. Basically I want this function to be called everytime a user tries to access something inside the modules directory.
You can use _remap() for this. You can put this in MY_Controller if you are using one, for more information read the Controller User Guide
Here is something you can start with.