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

[eluser]AntonioAntar[/eluser]
Hello

I'm new to using codeigniter. I did some research and I understand the URL structure to be as follows:

example.com/class/method/id

I understand how to create a main controller and subsequent methods and I also understand how to route to manipulate url structure as I want it to be.

However, when I create a second controller, I don't know how to acccess it on my local host. I will give the example I'm working with.

class Testsite extends CI_Controller {
public function index() {
//some code
}

function about() {
$this->load->view("about");
}

This is my main controller. I have access to both on my localhost. if I want to access my index page, I simply do http://localhost/testsite (I revmved index.php thorugh htacess) and if I want to access my about page I do http://localhost/testsite/about

Now into my second controller, the one I'm struggling with

class Test2 extends CI_Controller{

public function testing2(){
echo "hello";
}

}

So how can I access this controller on my localhost? i'm I missing something or doing something wrong? is there anything I have to do to connect the main controller and other controllers that I create? It there some sort of extension between controllers that I have to do? I did some search but I still couldn't figure it out

Any help will be greatly appreciated

Cheers
#2

[eluser]CroNiX[/eluser]
Just like your first one, using controller (which was testsite) and the method (which was about)

test2 is controller
testing2 is method (optional...if not included in url, it will look for an "index" method in the test2 class)

http://localhost/test2/testing2 should display your hello message
#3

[eluser]AntonioAntar[/eluser]
Hey,

I tried to do that but it gives me this message

Object not found!

The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

If you think this is a server error, please contact the webmaster.

Error 404

localhost
Apache/2.4.7 (Win32) OpenSSL/1.0.1e PHP/5.5.6

Do i have to extend the second controller differently perhaps? I have heard of the concept of child controller but I don't understand it. Or is there mabye something in the library that I have to do to get my secondary controllers to work?
#4

[eluser]CroNiX[/eluser]
And your class is located in /application/controllers/test2.php?

Does it work if you add the index.php to the url?
http://localhost/index.php/test2/testing2
#5

[eluser]AntonioAntar[/eluser]
yes it is located in same folder as my main controller testsite

I tried to put the index.php before it took me to the main page for xampp

I got rid of index.php for my main controller thorugh htaccess and I set my default index page to the main controller. So when I type localhost/testsite I get the index page for my main controller
#6

[eluser]Massaki[/eluser]
Did you make any change on your config/routes.php?
#7

[eluser]AntonioAntar[/eluser]
this is what I have in config/route.php

$route['default_controller'] = "testsite";
$route['404_override'] = '';




Theme © iAndrew 2016 - Forum software by © MyBB