Jump to content

RESOLVED: Problem with $wire->messages('clear all') on template


Entil`zha
 Share

Recommended Posts

Hi,

For some reason when I try to read and clear messages or errors in template I'll get the messages but they won't clear and will show after next page load.

I following code in my head.inc which is included in every template.

$messages = $wire->messages('clear all');
foreach ($messages as $m) {
echo '<div class="alert alert-success alert-dismissible" role="alert">';
  echo '<p class="badge badge-pill badge-success">OK</p> ' . $m->text;
  echo '<button type="button" class="close" data-dismiss="alert" aria-label="Close">';
  echo '<span aria-hidden="true">&times;</span>';
  echo '</button>';
  echo '</div>';
}

I'll get all the messages but they don't get cleared.

Only way to clear messages is to load page from admin area.

 

Link to comment
Share on other sites

  • 4 weeks later...
  • 4 years later...

Hi,

i have the same problem, but 

$session->removeAllFor('message') does not help, any idea?

function renderHeader() {
    $xtpl = new XTemplate('/templates/tmpl/header.tmpl');
 
    $session = wire('session');
    $messages = $session->messages('clear all');
   
    if (!empty($messages)) {
        foreach ($messages as $message) {
            $xtpl->assign('MESSAGE', $message->text);
            $xtpl->parse('header.messages.message');
        }
        $xtpl->parse('header.messages');
        $session->removeAllFor('message');
    }
 
    $xtpl->parse('header');
    return $xtpl->text('header');
}
 
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...