Angelo
Angelo

Reputation: 13

Base Controller error

I made a base controller and this error comes out.

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Form::$session

Filename: core/MY_Controller.php

Line Number: 7

Fatal error: Call to a member function userdata() on a non-object in C:\xampp\htdocs\ci_intro\application\core\MY_Controller.php on line 7

MY_Controller is this:

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

             class MY_Controller extends CI_Controller {
             function __construct(){
                 parent::__construct();

                     $user_data = $this->session->userdata('user_data');
                      $this->data['uname'] = $this->user_lib->get($id);
                 }
              }

What seems to be the problem here?Can anyone help me out?

Upvotes: 1

Views: 1117

Answers (1)

Pupil
Pupil

Reputation: 23948

You need to add session library in your controller.

$this->load->library('session');

Or

you can add it by default for whole project in

/application/config/autoload.php:

$autoload['libraries'] = array('session');

Also, go to /application/config/config.php and add a encryption key for you application:

$config['encryption_key'] = 'YOUR-ENCRYPTION-KEY';

Upvotes: 1

Related Questions