Welcome Guest, Not a member yet? Register   Sign In
Fatal error: Class 'Controller' not found PROBLEM - Need Help!
#1

[eluser]Jimster[/eluser]
Hi all

I really need some help quickly. I have been stuck now for 2 days with a port of an old website into the CI MVC framework.

I get the following error when I add a second controller. The error occurs when I launch the link on the welcome page to go to the test page.

<b>Fatal error: Class 'Controller' not found in C:\xampp\htdocs\Test\system\application\controllers\test.php on line 3</b>

<b>Is there something additional I need to do to get this second controller working?</B>


To reduce the code I downloaded a fresh version of CI 1.7.2 and I have modified it with the following controllers and views to exhibit the problem.

My environment is:

Windows 7
XAMPP

In config.php I changed $config['base_url'] = "http://localhost/Problem/";



<b>CONTROLLERS</b>

<b>welcome.php</b>

&lt;?php

class Welcome extends Controller {

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

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

<b>test.php</b>

&lt;?php

class Test extends Controller {

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

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


<b>VIEWS</b>

<b>message_view.php</b>

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Welcome to CodeIgniter&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

<h1>Welcome to CodeIgniter!</h1>

This is an anchor to the test page
<p><a href="system/application/controllers/test.php">To Test Page</a></p>

&lt;/body&gt;
&lt;/html&gt;


<b>test_view.php</b>

&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Test Page&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;

<h1>Test Page!</h1>

This is an anchor back to the Welcome page
<p><a href="welcome.php">To Welcome Page</a></p>

&lt;/body&gt;
&lt;/html&gt;


Thanks for the help

Jimster
#2

[eluser]danmontgomery[/eluser]
You shouldn't be linking to application/controllers/test.php, you would access your controllers at /test or /welcome. This is covered in the user guide.
#3

[eluser]Jimster[/eluser]
Hi

Thanks for the post

I am not fully understanding it.

Can you possibly post a complete URL as an example?

Thanks

Jim
#4

[eluser]danmontgomery[/eluser]
Quote:example.com/class/function/id/

So if your controller is Welcome,

example.com/index.php/welcome

Will call the default method, which is index(). This is identical to

example.com/index.php/welcome/index

To call another method, like foo(),

example.com/index.php/welcome/foo

etc
#5

[eluser]Jimster[/eluser]
hi again

I am not trying to access another method in the welcome controller class. I am trying to access another controller called test.

When I launch it seems to find the Test controller file OK but I get the error that in can't find the Controller class. In the welcome controller this class is found just fine. Its just when I try to access a second controller that I have this issue.

Sorry but I am totally confused.

I have this path in the config.php file
$config['base_url'] = "http://localhost/Problem/";

I use this anchor <left off the anchor tags>

In the view_welcome.php file <>href="system/application/controllers/test.php">To Test Page<>

I get this URL in the Browser when I click the link on the welcome page.

<b>http://localhost/Problem/system/application/controllers/test.php</b>

This is the right path so I think it is finding the file just fine. What I don't understand is why it can't find the Controller Class in the Test controller file but it works just fine in the Welcome controller. The Welcome controller is the default controller.

Jim
#6

[eluser]WanWizard[/eluser]
You are still referencing the file structure on disk. Don't, CI doesn't access files directly, everything passes through the front controller, index.php.

You should access your test controller via http://localhost/test.
#7

[eluser]Jimster[/eluser]
Finally understand how this works.

Thanks for the help.

Jimster
#8

[eluser]corneliusIV[/eluser]
[quote author="Jimster" date="1283982964"]Hi all

...
&lt;?php

class Welcome extends Controller {

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

function index()
{
$this->load->view('welcome_message');
}
}
...
Jimster[/quote]

I fixed this by changing controllers file:

class Welcome extends <b>Controller</b> {

to

class Welcome extends <b>CI_Controller</b> {

I am using CI 2.0 ;-)




Theme © iAndrew 2016 - Forum software by © MyBB