1
votes

I have a basic question regarding to configuring route in Codeigniter. In my application, I can route through $route['default_controller'] = "welcome"; perfectly fine. I can use it to route to different controller than welcome controllers as well. However, it does not allow me to route through any other route expressions apart from the default_controller.

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

$route['test'] = "welcome";
$route['default_controller'] = "welcome";
$route['404_override'] = '';

So as I have mentioned already, it takes me to welcome controller if my URL path is localhost/myproject , but it wouldn't let me navigate to the same controller using localhost/myproject/test. I hope you've understood my question.

Thanks in advance,

1
What it takes you to then? - itachi
$route['test'] = "welcome"; it takes me to 404 page. - Jason

1 Answers

1
votes

Make sure you have an index method in your Welcome controller to accept your route.

Also Codeigniter will handle many routes automatically. So if you went to localhost/myproject/test it will go to the test method of your default_controller. So removing that test route and adding the test method would fix this for you.

class Welcome extends CI_Controller
{ 
    public function __construct()
    {
    }

    public function index()
    {
    }

    public function test()
    {
        echo 'test method';
    }
}