Redirect prevents debug toolbar from loading

So for some odd reason, when I use the redirect function, the page rendered does not have the debug toolbar visible or functional.

I can see the ajax call being made and the response is as it should be, however, it is never rendered. When inspecting, the response is in one giant quote and interpreted as text vs HTML.

It only happens when the redirect is from ‘on BeforeAction’. Anywhere else, it works as intended.

How can I fix this?

'on beforeAction' => function ($event) {

        if (!Yii::$app->user->isGuest) {

            $route = Yii::$app->controller->getRoute();

            if (Yii::$app->user->identity->status == '5' && $route != 'site/email-confirmation' && $route

                != 'site/resend-email' && $route != 'site/confirm-email') {





Move this code from config to ParentController::beforeAction() and inherit from it all child controllers.

This solved it, thank you!

Question though, doesn’t this create another controller object vs having the code in the config?

Of course creates. You just create a layer between base yii\web\Controller and your controllers. In config this code ‘on beforeAction’ works at the Application::EVENT_BEFORE_ACTION level, while the ParentController::beforeAction() works at the Controller::EVENT_BEFORE_ACTION level. Thats why ParentController::beforeAction() doesn’t trigger debug-toolbar’s events.