I am trying to create a constructor for my controller, which refers to a function contained in the helper, which is automatically loaded.
The function checks if the user is logged in if he redirects them to the login page.
It looks like I did not set up the construct correctly, as I am getting the following error:
Fatal error: Call to undefined method Profile::is_logged_in()
This is the controller:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class Profile extends CI_Controller { public function __construct() { parent::__construct();
I only want the function inside the controller to be available if the user is logged in.
This is an auxiliary autoloader
$autoload['helper'] = array('url','array','html','breadcrumb','form','function','accesscontrol');
(accesscontrol_helper.php):
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); function is_logged_in() { $is_logged_in = $this->session->userdata('is_logged_in'); if(!isset($is_logged_in) || $is_logged_in != true) { echo 'You don\'t have permission to access this page. <a href="../login">Login</a>'; die();
Why am I unable to run this function? Does the helper code have a better method?
source share