4

I'm developping a website using CI and today I'm facing a problem in the admin part.

I've an admin and I can manage users

the structure of my application is:

controllers/admin/users.php

in users.php I've some functions: index(), view($id), login(), edit($id)

views/admin/users/index.php
views/admin/users/view.php
views/admin/users/login.php
views/admin/users/edit.php

to access the login page the url is:

www.mysite.com/admin/login

to access the list of users the url is:

www.mysite.com/admin/users

to view a specific user (id=5) the url is: www.mysite.com/admin/users/5

everything is working well except for the edit function, I got an url when I call www.mysite.com/admin/edit/5

here are my routing rules:

$route['admin/users/(:any)'] = 'admin/users/view/$1';
$route['admin/users'] = 'admin/users';

$route['admin/users/login'] = 'admin/users/login';

$route['admin/users/edit/(:num)'] = 'admin/users/edit/$1';

$route['admin'] = 'admin/users/login';

I miss something? what is wrong?

Kumar V
  • 8,810
  • 9
  • 39
  • 58
user3129131
  • 79
  • 2
  • 8
  • You might wanna look at remapping the function calls. http://ellislab.com/codeigniter%20/user-guide/general/controllers.html#remapping This can help you avoid using routing. – andershagbard Jan 10 '14 at 10:20

2 Answers2

2

Try putting it higher in the sequence, since route are matched top to bottom:

$route['admin'] = 'admin/users/login';
$route['admin/users'] = 'admin/users';
$route['admin/users/login'] = 'admin/users/login';
$route['admin/users/edit/(:num)'] = 'admin/users/edit/$1';
$route['admin/users/(:any)'] = 'admin/users/view/$1';

That :any might be catching too much and interfere, I'd leave it as a last catch-all route for all those non specified.

Damien Pirsy
  • 25,319
  • 8
  • 70
  • 77
  • Prego! :) If you find this answer solves your problem please consider marking it as "accepted" by using the thick mark under the vote count, so to show any future reader the solution to the problem – Damien Pirsy Jan 10 '14 at 11:14
0
$route['admin/users/(:any)'] = 'admin/users/view/$1';
$route['admin/users'] = 'admin/users';

$route['admin/users/login'] = 'admin/users/login';

$route['admin/edit/(:any)'] = 'admin/edit/view/$1';

$route['admin'] = 'admin/users/login';

Try this You might get results!

Nehil Mistry
  • 1,101
  • 2
  • 22
  • 51