I’m trying to display a flash message in the CP after being redirect from a controller.

Some context: when a user registers from a front-end, the account is set to “pending” and the admin gets a notification email. Inside the email, there’s a link “Activate this user” pointing to a controller action that performs the activation and redirect to the user CP page.

So far, so good! But I’d like to show a notification that tells the admin that the user has been activated. So my controller is something like this…

public function actionActivateUser() {


    // get the user and perform activation...

    $this->setSuccessFlash('Activation mail sent');
    return $this->redirect('admin/users/' . $user->id);

Activation works ok, but no message is shown. I’ve tried a few alternative methods like setFlash() or addFlash() without success. Am I missing something?

Thank you!

UPDATE: The flash message is set, if I redirect to a front-end template it gets displayed correctly, but CP pages ignore it. However, this works:

Craft::$app->session->addJsFlash(" Craft.cp.displayNotice('Activation email sent') ");

But I'm pretty sure it's not the right way to do it.

  • This should work. It might just be from your copy/paste but there is an apostrophe after the word sent instead of a single quote ', is that the problem?
    – Oli
    Jul 1, 2021 at 12:15
  • Just a typo, fixed.
    – gioppe
    Jul 1, 2021 at 13:13

1 Answer 1


In a controller method, setNotice works for me for this sort of thing.

Craft::$app->getSession()->setNotice(Craft::t('my-plugin', 'Activation mail sent'));
  • Tried, but unfortunately nothing changes.
    – gioppe
    Jul 1, 2021 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.