Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error Class Controller not found in CodeIgniter

Hello, I am getting Controller not found error in CodeIgniter. This is my Controller code

<?php

class HelloWorld extends Controller
{

    function HelloWorld()
    {
        parent::Controller();
    }

    function index()
    {
        $this->load->view('index_view');
    }

    function hello()
    {
        $this->load->view('hello_view');
    }

}
?>

This is the view code:

Hello, Nice to see you!

I have this error when it executes:

Fatal error: Class 'Controller' not found in D:\wamp\www\CodeIgniter_2.0.2\application\controllers\helloworld.php on line 2

Can anyone tell me why I get this error?

like image 276
Umer Singhera Avatar asked May 16 '26 23:05

Umer Singhera


1 Answers

As of CodeIgniter 2.x CI_ prefix is added to all core classes. Check the Change Log.

Added CI_ Prefix to all core classes.

For CodeIgniter 2.x

<?php

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

class HelloWorld extends CI_Controller
{

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

    function index()
    {
        $this->load->view('index_view');
    }

    function hello()
    {
        $this->load->view('hello_view');
    }

}

For CodeIgniter 1.x

<?php

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

class HelloWorld extends Controller
{

    function HelloWorld()
    {
        parent::Controller();
    }

    function index()
    {
        $this->load->view('index_view');
    }

    function hello()
    {
        $this->load->view('hello_view');
    }

}

Hope this helps you. Thanks!!

like image 157
Madan Sapkota Avatar answered May 19 '26 12:05

Madan Sapkota



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!