1

I created a helper "session_helper.php" in application/helpers/ folder

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('is_login'))
{
    function is_login()
    {
        $CI =& get_instance();

        $is_logged_in = $CI->session->userdata('is_logged_in');

        if (!isset($is_logged_in) || $is_logged_in != TRUE) { 

            redirect('login');

        }               

    }   
}

And "Configuracion" Controller:

class Configuracion extends CI_Controller {

    function __construct()
    {
            parent::__construct();

            $this->is_logged_in();  
    }

    function is_logged_in()
    {
        $this->load->helper('session');

        $this->is_login();

    }       

} 

The problem is when I call the controller "http://localhost/proyect/configuracion" I get the following error:

Fatal error: Call to undefined method Configuracion::is_login() in C:...\application\controllers\configuracion.php on line 15

I read the manual and apparently everything is correct ... what is wrong?

2 Answers 2

4

"is_login" is a function, not a method. Just replace $this->is_login(); with is_login();.

Sign up to request clarification or add additional context in comments.

Comments

1

Helpers are not methods, they are just simple function calls.

Take a look at helpers in the User Guide: http://codeigniter.com/user_guide/general/helpers.html

Loading a helper:

$this->load->helper('url');

using its helper functions:

<?php echo anchor('blog/comments', 'Click Here');?>

where anchor() is the function that is part of the loaded helper.

Also I would urge you to stay way from calling a helper 'session' make it something more descriptive, as it might become confusing later on. Just a suggestion, its entirely up to you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.