views:

894

answers:

2

UPDATE: SOLVED! For the broken pages I simply made an admin controller. That has a function for each model now :) Happy days!

Trying to house my admin function in the same controller as my front-end code. To do this I am setting up some custom routes so that admin can be accessed via:

/admin/controller/id // instead of /controller/admin/id
/admin/controller/create // instead of /controller/create
/admin/controller/detail/id // instead of /controller/detail/id
/admin/controller/update/id // instead of /controller/update/id
/admin/controller/delete/id // instead of /controller/delete/id

My current routes work perfectly for detail, create, update, delete

$route['admin/(:any)/detail'] = "$1/detail"; // WORKS!!!
$route['admin/(:any)/detail/(:num)'] = "$1/detail/$2"; // WORKS!!!
$route['admin/(:any)/create'] = "$1/create"; // WORKS!!!
$route['admin/(:any)/create/(:num)'] = "$1/create/$2"; // WORKS!!!
$route['admin/(:any)/update'] = "$1/update"; // WORKS!!!
$route['admin/(:any)/update/(:num)'] = "$1/update/$2"; // WORKS!!!
$route['admin/(:any)/delete'] = "$1/delete"; // WORKS!!!
$route['admin/(:any)/delete/(:num)'] = "$1/delete/$2"; // WORKS!!!

HOWEVER I cannot get the admin page to work with an ID. I can reroute the index page, but will be unable to use pagination if I cannot pass the ID.

$route['admin/(:any)'] = "$1/admin"; // WORKS!!!
$route['admin/(:any)/(:num)'] = "$1/admin/$2"; // EPIC FAIL :( 404's

Can someone please help me solve this problem, or even suggest an alternative solution of application structure.

A: 

If your admin is complicated and you need several controllers for it, you can simply create an admin folder in your application/controllers folder. Then put your admin controllers in that.

So application/controllers/admin/login would work like http://example.com/admin/login

dprevite
Hi, That is the approach I was taking initially, but I wanted to change my approach on a new project and keep CRUD functions within the front-end controller. So I have one controller per function.
esryl
+1  A: 

Make sure your regex routes (that includes routes with :num and :any) must go AFTER the default_controller route.

For more ways to create a decent admin panel, take a look at my article on creating an admin panel in CodeIgniter. There are three decent ways to do it, this article explains the pro's and con's of each.

Phil Sturgeon
:) It was that article that solved my little problem. Thanks for checking in ;)
esryl