$notices API variable / Notices class

A class to contain multiple Notice instances, whether messages, warnings or errors

This class manages notices that have been sent by Wire::message(), Wire::warning() and Wire::error() calls. The message(), warning() and error() methods are available on every Wire derived object. This class is primarily for internal use in the admin. However, it may also be useful in some front-end contexts.

// Adding a NoticeMessage using object syntax
$notices->add(new NoticeMessage("Hello World"));

// Adding a NoticeMessage using regular syntax
$notices->message("Hello World");

// Adding a NoticeWarning, and allow markup in it
$notices->message("Hello <strong>World</strong>", Notice::allowMarkup);

// Adding a NoticeError that only appears if debug mode is on
$notices->error("Hello World", Notice::debug); 

Iterating and outputting Notices:

foreach($notices as $notice) {
  // skip over debug notices, if debug mode isn't active
  if($notice->flags & Notice::debug && !$config->debug) continue;
  // entity encode notices unless the allowMarkup flag is set
  if($notice->flags & Notice::allowMarkup) {
    $text = $notice->text;
  } else {
    $text = $sanitizer->entities($notice->text);
  }
  // output either an error, warning or message notice
  if($notice instanceof NoticeError) {
    echo "<p class='error'>$text</p>";
  } else if($notice instanceof NoticeWarning) {
    echo "<p class='warning'>$text</p>";
  } else {
    echo "<p class='message'>$text</p>";
  }
}

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the Notices class also inherits all the methods and properties of: WireArray and Wire.

Show $var?             Show args?        

Additional methods and properties

In addition to the methods and properties above, Notices also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.200

Twitter updates

  • New post: Multi-language field translation export/import — In this post we cover the details of a new module that enables export and import capabilities for multi-language fields in ProcessWire… More
    5 August 2022
  • Weekly update, July 29: Continuing upgrades to ProcessWire’s comments system and FormBuilder, along with a working example—More
    29 July 2022
  • Weekly update for July 22– Looking back at what web development was like in the year 2000. Plus some more discussion on the path from CKEditor 4 to CkEditor 5 in ProcessWire: More
    22 July 2022

Latest news

  • ProcessWire Weekly #430
    In the 430th issue of ProcessWire Weekly we're going to check out some brand new third party modules, a new site of the week, and more. Read on!
    Weekly.pw / 7 August 2022
  • Multi-language field translation export/import
    In this post we cover the details of a new module that enables export and import capabilities for multi-language fields in ProcessWire.
    Blog / 5 August 2022
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK