2

I've written a plugin that imports a CSV and creates entries from that for a client. I'm wanting to redirect them to the entries listing page after (i.e. /admin/entries/tvListings) and show a flash message saying "X TV listings imported.".

So this is a 2 parter:

  1. How do you set flash data in Craft 3.
  2. Is there a default flash key that'll show as soon as I land on the entries listing page?

Thanks.

6

To show a message

Craft::$app->getSession()->setNotice($message);

To show an error

Craft::$app->session->setError($message);

There is no "default" key that is always shown or something like that. You just use the function and set a message -> the next time the user visits any page the message is shown.

| improve this answer | |
  • Hi Robin - that doesn't seem to work for me. I set the flash message then redirect away with '\Craft::$app->controller->redirect("/admin/entries/tvListings");' and I get no flash message. – JamesNZ Apr 4 '18 at 20:54
  • I'm really sorry... I messed up the functions. Please see my update – Robin Schambach Apr 4 '18 at 20:59
  • You're a gentleman and a scholar. That worked perfectly. Thanks Robin. – JamesNZ Apr 4 '18 at 23:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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