A
A
Alex Mirgorodskiy2018-10-15 13:35:49
Yii
Alex Mirgorodskiy, 2018-10-15 13:35:49

How to change controller path in yii2?

Hello everyone, who has been familiar with Yii2 for a long time and deeply, do not tell me how best to implement a dynamic change in the controllers folder, say If there is a variable in the session, take controllers from the
/app/controller/ folder. $_session['controller'] . / . $controller->id , if not then /app/controller/default/$controller->id
Where does the controller open at all? I dug into the urlManager there only processing requests and building routes, but where does the process of opening the controller take place? Is it possible to do this somehow without breaking the logic of the framework?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-10-15
@webinar

You can change the namespace of the default controller in the config, you can change it in the module if it is the controller of the module. It is possible in beforeRequest. You can generally collect different configs at the entry point. But I think you're doing some kind of game. Describe the task in more detail.
Perhaps you should just redirect to the desired controller?
But still, probably the most adequate method is to change the controllerNamespace when initializing the module:
https://www.yiiframework.com/doc/api/2.0/yii-base-...
or controllerMap:
https://www.yiiframework.com /doc/api/2.0/yii-base-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question