M
M
muhasa2020-04-11 22:36:16
PHP
muhasa, 2020-04-11 22:36:16

How to set the same routes for different roles in slim framework?

Hello.
I'm doing a project on slim framework 3 , there is quite a decent routing.
The task is as follows - there are 4 roles (admin, moderator, doctor, client).
Inside the project, each one gets into a Dashboard with widgets peculiar to his role during authorization. But I would like the route to be the same for all roles - project.ru/dashboard
Of course, the problem can be solved by grouping routes by roles, for example
project.ru/client/dashboard
project.ru/doctor/dashboard

But I want to make it more elegant.

I didn’t do this before, so I’m interested in best practices, but I came up with one solution, I ask for the opinion of experienced people:
Controllers will be called
ClientController
DoctorController
etc.

In the routes.php file, make a mechanism for determining the role of an authorized user and substitute it in the controller name, and there each route will call its own set of services.
Or is that not it?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question