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
7
  • Do you want all of the URLs to exactly have the letter 'u' after the website? Commented Feb 20, 2017 at 15:47
  • You need to merge your controllers or have different URLs... Commented Feb 20, 2017 at 15:49
  • 'u' is not recommended, i just want to hide controller name Commented Feb 20, 2017 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 Commented Feb 20, 2017 at 16:51
  • ok, which structure should i use? Commented Feb 20, 2017 at 16:56

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes I know, Actually I don't want to show roles in URL
0

you wanted to do like this routing ?

   $route['u/(:any)'] = "admin/method";
   $route['u/(:any)'] = "editor/method";

2 Comments

Yes, i think it is not possible
Is it possible to do like this ? $route['u/(:any)'] = "$_SESSION['role']/method"; $route['u/(:any)'] = "$_SESSION['role']/method";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.