Welcome Guest, Not a member yet? Register   Sign In
Multiple Controllers
#1

[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
#2

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

[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
#4

[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
#5

[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
#6

[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.




Theme © iAndrew 2016 - Forum software by © MyBB