, (*1)
, (*2)
Install
Using Composer, (*3)
composer require suxiaolin/notify
Add the components to config/main.php
, (*4)
'notifier' => [
'class' => 'suxiaolin\notify\Notifier',
]
Note, there is a Notifier::instance() function available, so you can via Notifier::instance() instead of config it in config/main.php
., (*5)
Usage
Basic
From your application, call the flash
method with a message and type., (*6)
Notifier::instance()->flash('Welcome back!', 'success');
Within a view, you can now check if a flash message exists and output it., (*7)
<?php if (Notifier::instance()->ready()): ?>
<div class="alert-box <?= Notifier::instance()->type() ?>">
<?= Notifier::instance()->message() ?>
</div>
<?php endif; ?>
Notify is front-end framework agnostic, so you're free to easily implement the output however you choose., (*8)
Options
You can pass additional options to the flash
method, which are then easily accessible within your view., (*9)
Notifier::instance()->flash('Welcome back!', 'success', [
'timer' => 3000,
'text' => 'It\'s really great to see you again',
]);
Then, in your view., (*10)
<?php if (Notifier::instance()->ready()): ?>
<script>
swal({
title: "<?= Notifier::instance()->message() ?>",
text: "<?= Notifier::instance()->option('text') ?>",
type: "<?= Notifier::instance()->type() ?>",
<?php if (Notifier::instance()->option('timer')): ?>
timer: <?= Notifier::instance()->option('timer') ?>,
showConfirmButton: false
<?php endif; ?>
});
</script>
<?php endif; ?>
, (*11)
The above example uses SweetAlert, but the flexibily of Notify means you can easily use it with any JavaScript alert solution., (*12)
Issues and contribution
Just submit an issue or pull request through GitHub. Thanks!, (*13)