1. Go to this page and download the library: Download tamtamchik/simple-flash 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/ */
use \Tamtamchik\SimpleFlash\Flash;
use function Tamtamchik\SimpleFlash\flash;
// Instance
$flash = new Flash();
$flash->message('Tea.');
// Static
Flash::message('Earl Gray.');
// Function
flash()->message('Hot!');
use function Tamtamchik\SimpleFlash\flash;
flash()->error(['Invalid email!', 'Invalid username!'])
->warning('Warning message.')
->info('Info message.')
->success('Success message!');
use function Tamtamchik\SimpleFlash\flash;
// Rendering specific type
$output = flash()->display('error');
// Rendering all flash
$output = flash()->display();
// Also rendering possible when you just read instance of \Tamtamchik\SimpleFlash\Flash object as a string
(string) flash();
// or ... it's totally just for display, never do this in real life...
// ... some code
$flash = new Flash();
$flash->warning('It is totally just for display, never do this in real life...');
// ... some other code
use function Tamtamchik\SimpleFlash\flash;
flash()->success('Success message!');
...
// rendering with Halfmoon template using Templates::HALFMOON as a shortcut
echo flash()->display('success', Templates::HALFMOON);
use Tamtamchik\SimpleFlash\Flash;
use Tamtamchik\SimpleFlash\TemplateFactory;
use Tamtamchik\SimpleFlash\Templates;
// get template from factory, e.g. template for Foundation
$template = TemplateFactory::create(Templates::FOUNDATION);
// passing template via function
flash('Info message using Foundation 6 template!', 'info', $template);
// passing to constructor
$flash = new Flash($template);
// using setTemplate function
$flash->setTemplate($template);
use Tamtamchik\SimpleFlash\BaseTemplate;
use Tamtamchik\SimpleFlash\TemplateInterface;
use function Tamtamchik\SimpleFlash\flash;
class CustomTemplate extends BaseTemplate implements TemplateInterface
{
protected $prefix = '<li>'; // every line prefix
protected $postfix = '</li>'; // every line postfix
protected $wrapper = '<ul class="alert-%s">%s</ul>'; // wrapper over messages of same type
/**
* @param $messages - message text
* @param $type - message type: success, info, warning, error
*
* @return string
*/
public function wrapMessages($messages, $type)
{
return sprintf($this->getWrapper(), $type, $messages);
}
}
flash()
->setTemplate(new CustomTemplate)
->error(['Invalid email!', 'Invalid username!'])
->warning('Warning message.')
->info('Info message.')
->success('Success message!')
->display();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.