Mecha CMS

Mecha CMS blog and documentation.

Class Notify

Updated: Sunday, 07 August 2016

Notification messages.

This class is used to display notification messages which will appear once per page visit, usually just after something has been submitted.

Set

Notify::info('This is an info message.');

Get

echo Notify::read();

Stacking

Notify::success('This is a success message.');
Notify::info('This is an info message.');
Notify::warning('This is a warning message.');
Notify::error('This is an error message.');

echo Notify::read();

Clearing

Notify::clear();

Counting Errors

When error and warning messages displayed, it will also increase the internal value of $errors variable inside the Notify class in the background. This is useful for limiting actions only if no errors occurred:

if( ! Notify::errors()) {
    echo 'It is OK.';
}

Custom Notification Message

// create
Notify::plug('my_custom_message', function($text, $icon = 'bell-o') {
    Notify::bare($text, $icon, 'custom-class');
});

// usage
Notify::my_custom_message('Hello there!');

// print
echo Notify::read();

Result:

<div class="messages cl cf">
  <p class="message cl cf">
    <i class="fa fa-fw fa-bell-o"></i> Hello there!
  </p>
</div>

Email Notification

Added since version 1.1.0.

$from = 'from@email.com';
$to = 'to@email.com';
$subject = 'New message!';
$message = 'Test message.';

if(Notify::send($from, $to, $subject, $message)) {
    echo 'Sent!';
}
Donation and Email Subscription