0

I am working on a back-end Admin Panel using codeigniter and in admin panel there are multiple user roles like Admin, Editor, Manager etc. Now i have created multiple controller for each roles like:

  • controllers/Admin.php
  • controllers/Editor.php
  • controllers/Manager.php

So, URL become like this

  • www.mysite.com/admin/anyfunction
  • www.mysite.com/editor/anyfunction
  • www.mysite.com/manager/anyfunction

But i want these URLs like

  • www.mysite.com/u/anyfunction
  • www.mysite.com/u/anyfunction
  • www.mysite.com/u/anyfunction
  • Do you want all of the URLs to exactly have the letter 'u' after the website? – coderszx Feb 20 '17 at 15:47
  • You need to merge your controllers or have different URLs... – Callombert Feb 20 '17 at 15:49
  • 'u' is not recommended, i just want to hide controller name – Suraj Bharti Feb 20 '17 at 16:01
  • You could put a redirect at the top of each controller that checks if the user has the correct role to access that controller, and if not you redirect them to the appropriate controller, for example for Admin.php in your function `if($user->editor) {redirect('editor/index')}` and `if($user->manager) {redirect('manager/index')}` Ultimately I'd suggest you find a different structure though that doesn't require all these redirects though – Pacio Feb 20 '17 at 16:51
  • ok, which structure should i use? – Suraj Bharti Feb 20 '17 at 16:56
  • Maybe [this answer](http://stackoverflow.com/a/13351061/3585500) is what you're after? – ourmandave Feb 20 '17 at 19:39
  • there are many methods in every controllers and there would be some common method – Suraj Bharti Feb 21 '17 at 05:17

2 Answers2

0

In your scenario function names must be different. But having different function names you can just make routes as

$route['u/any-method'] = "admin/any_method";
$route['u/some-other-method'] = "editor/any_method"; 

URL need to be different to allow Router class to resolve which part of code should be executed. Check here in docs.

Tpojka
  • 6,996
  • 2
  • 29
  • 39
0

you wanted to do like this routing ?

   $route['u/(:any)'] = "admin/method";
   $route['u/(:any)'] = "editor/method";
Amit Chauhan
  • 682
  • 7
  • 22