<p>In a controller method, <code>setNotice</code> works for me for this sort of thing.</p>
<pre><code>Craft::$app-&gt;getSession()-&gt;setNotice(Craft::t('my-plugin', 'Activation mail sent'));
</code></pre>

CC BY-SA 4.0
2021-07-01T13:18:11.353Z
Tried, but unfortunately nothing changes.
gioppe
CC BY-SA 4.0
2021-07-01T13:01:57.717Z
2021-07-01T13:01:57.717Z
Martin Spain
<p>I’m trying to display a flash message in the CP after being redirect from a controller.</p>
<p>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.</p>
<p>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…</p>
<pre><code>public function actionActivateUser() {

    $this-&gt;requireAdmin();

    // get the user and perform activation...

    $this-&gt;setSuccessFlash('Activation mail sent');
    return $this-&gt;redirect('admin/users/' . $user-&gt;id);
}
</code></pre>
<p>Activation works ok, but no message is shown. I’ve tried a few alternative methods like <code>setFlash()</code> or <code>addFlash()</code> without success. Am I missing something?</p>
<p>Thank you!</p>
<p>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:</p>
<pre><code>Craft::$app-&gt;session-&gt;addJsFlash(&quot; Craft.cp.displayNotice('Activation email sent') &quot;);
</code></pre>
<p>But I'm pretty sure it's not the right way to do it.</p>

CC BY-SA 4.0
2021-07-01T12:15:42.647Z
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
CC BY-SA 4.0
2021-07-01T13:13:29.093Z
Just a typo, fixed.
gioppe
<controller><flash>
Set flash message after redirect
# Set flash message after redirect

(Asked by: username_0 on 2021-07-01)

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() {

    $this->requireAdmin();

    // 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.

**Tags:** controller, flash
> **Comments:**
> **username_1**: 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?  
> **username_0**: Just a typo, fixed.  

---

## 1 answers

### Answer by username_2 on 2021-07-01. Score: 2

In a controller method, setNotice works for me for this sort of thing.
Craft::$app->getSession()->setNotice(Craft::t('my-plugin', 'Activation mail sent'));

> **Comments:**
> **username_0**: Tried, but unfortunately nothing changes.  

---

