PHP code example of werx / messages

1. Go to this page and download the library: Download werx/messages library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

werx / messages example snippets



use werx\Messages\Messages;

// Import the composer autoloader, if you aren't already using it.

Messages::error('Oops, something bad happened.');
Messages::info('Nothing big, this is just an informational message.');
Messages::warning('A little more serious than info, but not quite an error.');
Messages::success('Hooray! This is a success message.');
Messages::success('Here is another success message.');

Messages::error('The quick %s %s jumped over the %s.', ['brown', 'fox', 'log']);

// The quick brown fox jumped over the log.

Messages::error('The quick brown fox jumped over the %s.', 'lazy dog');

// The quick brown fox jumped over the lazy dog.

Messages::warning(['This is a warning.', 'This is also a warning.']);

// This is a warning.
// This is also a warning.

$items = Messages::all();
print_r($items);

/*
Array
(
	[error] => Array
		(
			[0] => Oops, something bad happened.
		)

	[info] => Array
		(
			[0] => Nothing big, this is just an informational message.
		)

	[success] => Array
		(
			[0] => Hooray! This is a success message.
			[1] => Here is another success message.
		)

	[warning] => Array
		(
			[0] => A little more serious than info, but not quite an error.
		)

)
*/

$display = Messages::display();
print $display;

Messages::setDecorator(new Decorators\Bootstrap);
$display = Messages::display();
print $display;

// Create a new session object.
$session = new \Symfony\Component\HttpFoundation\Session\Session(
				new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage(['cookie_lifetime' => 604800])
);

Messages::getInstance($session);