How to use HTML inside ZF2 FlashMessenger

1.1k Views Asked by At

I want to use an <a> inside a flashMessenger message.

For example: In my website I have some blog posts, and when I delete one of them, I want to show a message like: "Success! <a>Undo</a>"

My code:

  $restore = $this->url()->fromRoute('news/restore', array('id' => $id));
  $this->flashMessenger()->addSuccessMessage("Success. <a href='$restore'>Undo</a>");
  return $this->redirect()->toRoute('news');

But It doesn't work when I put that <a> inside the message. How can I do that?

1

There are 1 best solutions below

2
morrsky On BEST ANSWER

The way it worked for me:

<?php if($this->flashMessenger()->hasMessages()): ?>

    <div class="alert alert-info flash-messenger">
        <?=$this->flashMessenger()->setAutoEscape(false)->render(); ?>
    </div>

<?php endif; ?>

By default the autoEscape property is set to true

Factory? Maybe?

source:

https://github.com/zendframework/zend-view/blob/master/src/Helper/FlashMessenger.php