3

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 )

3
  • 1
    What steps are you taking to get to this code? Are you sure you're directing this through index.php instead of accessing this file directly? Commented Sep 2, 2010 at 23:31
  • 3
    @rabidmachine closing the php tag is optional and sometimes it is helpful check this out us.php.net/basic-syntax.instruction-separation I don't think thats the problem Commented Sep 3, 2010 at 0:03
  • @treeface it seems that this is the problem, I was accessing this file directly, but using this route generates page not found? 127.0.0.1:8000/test_ci/index.php/welcome I am installing now WAMP guessing the problem in my routing! Commented Sep 3, 2010 at 0:09

5 Answers 5

4

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');
    }
}
Sign up to request clarification or add additional context in comments.

Comments

2

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!

Comments

2

Because you are using the code for the older version of CodeIgniter so use this:

class Hello extends CI_Controller
{
    var $name;
    var $color;
    function Hello()
    {
        parent :: __construct();
        $this->name = "Name";
        $this->color = "red";
    }
    function you()
    {
        $data["name"] = $this->name;
        $data["color"] = $this->color;
        $this->load->view("you_view", $data);
    }

}

Comments

1

extend CI_Controller instead of Controller I was having the same problem in code ignitor before I switched to CI_Controller

Comments

0

It seems like you have Codeigniter in a different folder than '/'. If you don't change the BASEPATH or system root path in index.php or config.php, that will lead to problems.

Check lines 14-26 (?) in index.php for the "system" variable.

/*
|---------------------------------------------------------------
| SYSTEM FOLDER NAME
|---------------------------------------------------------------
|
| This variable must contain the name of your "system" folder.
| Include the path if the folder is not in the same  directory
| as this file.
|
| NO TRAILING SLASH!
|
*/
    $system_folder = "system";

Change that to reflect the path of your system folder and CI will surely find your controller class.

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.