S
S
Shurik2021-07-30 21:35:40
Yii
Shurik, 2021-07-30 21:35:40

How to make a redirect to one page from any other depending on the model property?

Hello!
The task is to make a redirect from any application route to a specific page that notifies the user that the site is under maintenance.
I implement it like this:
1. Created a table (and the model corresponding to it) with one record, in which the id of the application state. Let's say id=2 corresponds to maintenance mode.
2. Made a web interface for the admin where this parameter can be changed.
After that, I ran into the problem of how to give all users except the admin a page announcing that work is being done on the site.

I would like to get the state id from the above model, check it and the user's role, and, if necessary, redirect to the desired page. I know about the decision to make the class inherited from Controller and define the beforeAction method in it, which will contain all the logic, and the rest of the controllers will inherit from it, but too many controllers have already been created and I would like to do something differently!

Alternatively, the config contains the "catchAll" property, which redirects any request to the required route. This is a half measure, because I would like to do it from the web interface.

I tried to make a component and hang a handler on one of the application events and process conditions in the callback, but it was not possible to redirect from the component to the desired page.

I would be grateful for any hints in overcoming my problem))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Shurik, 2021-07-31
@svisch

Found the answer to the question here
Thank you all!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question