0

I am new to codeIgniter and facing issue while extending a controller. I do know there is answer on stackoverflow but it is relevant to extending a core class and does not provide me solution. As given below, I want to extend 'Auth_controller' but doing so gives me class not found error

MY Auth_controller

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



abstract class  Auth_Controller extends CI_Controller {


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

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

    if(!$this->session->userdata('u_id')){
        return redirect(base_url('admin/login'));
    }
    else
    {
        if(!$this->login_model->do_check_login($this->session->u_id,$this->session->email,$this->session->session_id,$this->session->role_id))
        {
            return redirect(base_url('admin/login'));

        }
        echo "login successful";

    }



}

public abstract function index();

}

My Dashboar_controller

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


class Dashboard_controller extends Auth_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->library('email');
        $this->load->library('calendar');
    }

    public function index()
    {
        //my code here
    }
}


error

Fatal error: Class 'Auth_Controller' not found in C:\xampp1\htdocs\Admin\application\controllers\admin\Dashboard_controller.php on line 4

Error Image

Sparky
  • 98,165
  • 25
  • 199
  • 285
Arsii Rasheed
  • 324
  • 1
  • 5
  • 18
  • https://stackoverflow.com/q/21351808/594235 – Sparky Jun 17 '18 at 15:28
  • https://stackoverflow.com/a/27910751/594235 – Sparky Jun 17 '18 at 15:35
  • Maybe look at the docs too. https://codeigniter.com/user_guide/general/controllers.html#organizing-your-controllers-into-sub-directories – Sparky Jun 17 '18 at 15:36
  • is `Auth_Controller` in `application/core`? in such a case you should either call it `MY_Controller` or require it in a file that is always loaded, like the config.php. – Alex Jun 17 '18 at 20:22

1 Answers1

1

You probably need to add require_once('Auth_controller.php') at the top of Dashboard_controller.php; otherwise the Dashboard file will not know about the Auth class. (See require_once in the php docs).

https://stackoverflow.com/a/27910751/594235

Sparky
  • 98,165
  • 25
  • 199
  • 285
Dominic Price
  • 1,111
  • 8
  • 19