Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeigniter, php5, Fatal error: Class 'Controller' not found

Fatal error: Class 'Controller' not found in <local_path>\system\application\controllers\welcome.php on line 3

<?php

class Welcome extends Controller {

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

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

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */

I am beginner in php frameworks just extracted the CodeIgniter zip file and tried to run welcome.php controller in Aptana studio. ( PHP 5 )

like image 720
Brary Avatar asked Dec 07 '25 09:12

Brary


2 Answers

No need to define constructor of class. This is the code for codeigniter 2.0 or later framework.

class Welcome extends CI_Controller {

    public function index()
    {
        $this->load->view('welcome_message');
    }
}
like image 182
Pushkar Avatar answered Dec 08 '25 23:12

Pushkar


the problem was that I am accessing this file directly (like what 'treeface' said), but using this route generates page not found?

127.0.0.1:8000/test_ci/index.php/welcome

then I installed WAMP and used

localhost/test_ci/index.php/welcome

and this is working!
sorry for the inconvenience!

like image 29
Brary Avatar answered Dec 08 '25 21:12

Brary



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!