M
M
Mysterion2018-04-25 18:33:42
Yii
Mysterion, 2018-04-25 18:33:42

How to implement dynamic loading actions?

Hello.
What do you think is the best way to implement access to Actions from the database in Yii2?
Let's say there are 5 actions in total:

  • payment
  • Settings
  • Index
  • Create
  • Delete

The number of actions can grow and actions should only be made available depending on the service that is passed to them as an ID.
There is a certain service, it is passed to the action as a GET parameter, the parent of the service is obtained through relations and the actions available for this parent are taken in the database.
How to pass them to the controller correctly?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Artem, 2018-04-25
@proudmore

The controller has an actions() method that partially defines the list of actions available in the controller. You can put all actions in Standalone classes , make a base class, inside which you can check if there is access to this action.
But I would be interested to hear why you need such a solution at all? There are a lot of access control tools out there! Yes, take at least RBAC .

M
Maxim Timofeev, 2018-04-25
@webinar

yii\filters\AccessControl
https://www.yiiframework.com/doc/api/2.0/yii-filte...
You pass the actions array to it, so all that's left is to add your logic for forming this array.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question