CodeIgniter Forums
Multiple Controllers - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Multiple Controllers (/thread-33755.html)



Multiple Controllers - El Forum - 09-07-2010

[eluser]Jimster[/eluser]
Hello

I'm new to CI so this may be newbie headset problem.

I have two controller files

<b>home.php code</b>

&lt;?php

class Home extends Controller {

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

function index()
{
$data['title'] = 'NSBAUSA - Home';
$this->load->view('view_home', $data);
}
}


<b>nsba_login.php code</b>

&lt;?php

class NSBA_Login extends Controller {

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

function index()
{
$data['title'] = 'NSBAUSA - Login';
$this->load->view('view_login', $data);
}
}


On the home page view I have a link to the login page.
When I launch the login link on the home page I get the following error.

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

What code do I have to change in the second controller file to make this work?
Can I have multiple controllers?
Am I making a bad assumption on implementing multiple controllers?

Thanks for the help

Jimster


Multiple Controllers - El Forum - 09-07-2010

[eluser]danmontgomery[/eluser]
The class name of the controller needs to match the filename. login.php should be nsba_login.php


Multiple Controllers - El Forum - 09-07-2010

[eluser]Jimster[/eluser]
Hi

Thanks for the reply

My bad in the initial post.

The file name is NSBA_login.php like it is listed in the error message. I made a mistake in the post. The php file should have been NSBA_login.php.

So I have the file name the same name as the class but I still get this error message.


Jim


Multiple Controllers - El Forum - 09-07-2010

[eluser]Jimster[/eluser]
Hi all

Can I get any more help on this issue from the community. It is stopping progress in porting an old website into the CI framework.

Any help would really be appreciated.

I am on Windows 7 using XAMPP

Jimster


Multiple Controllers - El Forum - 09-08-2010

[eluser]smilie[/eluser]
Well, try this:

class NSBA_Login extends Controller
filename: NSBA_login.php

Change filename to NSBA_Login.php

Not sure, but I think I read somewhere that it looks for exactly same name (lower / upper case).
Also, try to use different controller / file name, just for the test i.e. Abccontroller -> Abccontroller.php

Good luck.

Regards,
Smilie


Multiple Controllers - El Forum - 09-08-2010

[eluser]WanWizard[/eluser]
The router does a file_exists() check using the name specified in the URI.

So if you request http://hostname/nsba_login/method, it will check for a file called nsba_login.php. If your file is called NSBA_login.php, it will find it on Windows (because the filesystem is case insensitive), it will fail on linux (filesystem is case sensitive).
As a standard practice, ALWAYS use lowercase filenames.

As for the class name, the same applies. The router class doesn't do conversions, it uses the same URI segment to instantiate the controller class.
Fortunately, while variable names in PHP are case sensitive, class names are not, so you can get away with a controller class NBSA_login.