2
votes

It is the first time I'm trying to build an admin panel with CodeIgniter and I got stuck with a routing issue. In my controllers folder I have an admin folder and there's an admin.php file with an Admin class. This class has two methods, index() and dashboard(). I added a new route in routes.php like $route['admin'] = 'admin/admin'.

So far so good. Why I run http://mysite.com/admin/ it displays the login page, which is ok. But then, I can't display the dashboard using http://mysite.com/admin/dashboard. Instead I have to use http://mysite.com/admin/admin/dashboard which is crappy.

Is there any way I can get rid of the second "admin" in the url?

Thank you.

2

2 Answers

4
votes

Sure - create a specific route for the dashboard, i.e:

$route['admin/dashboard'] = 'admin/admin/dashboard';

Just remember that the router will choose the first matching route that it finds, so be wary of things like $route['admin/(:any)'] appearing before the dashboard route.

0
votes

i wouldnt do this. if you want a url such as http://domain.com/admin then in your routes.php file add the following

$route['admin'] = 'admin/dashboard';

then in your controllers folder, create a folder called admin, in there create a file called dashboard.php and extend the codeigniter class as normal