Toast Bootstrap5
Bootstrap 5 toast notifications from flash messages
Renders Bootstrap 5 toast notifications from your Yii3 application’s session flash messages. Queue
a message from a controller with FlashToastInterface, render it in your layout with
$toast->render($this). No manual partials, no bundled JS asset. Requires Bootstrap 5’s JS bundle
to be loaded on the page for the dismiss and auto-hide behavior.
Types
The first argument to add() is a ToastType case. Each maps to a Bootstrap 5 text-bg-* color
and an ARIA live-region role. Urgent types interrupt with role="alert", the rest announce
politely with role="status".
ToastType::SUCCESS
text-bg-successPolite status message (
role="status").ToastType::ERROR
text-bg-dangerUrgent alert (
role="alert"); stays up until dismissed by default, so it isn't lost to a timer.ToastType::WARNING
text-bg-warningUrgent alert (
role="alert").ToastType::INFO
text-bg-infoPolite status message (
role="status").Features
Flash-backed queue
Queue success/error/warning/info messages onto the session flash; multiple messages of the same type stack as separate toasts
Zero-config rendering
$toast is injected into every web view via the config-plugin, and its render() returns empty when no messages are pendingPer-type styling
Each type maps to a Bootstrap 5 text-bg-* color with the correct alert role/aria-live and close-button contrast
Configurable auto-dismiss
Per-type delay in milliseconds, or null to require manual dismissal (the default for error, so it isn't lost to a timer)
Optional icons
Bootstrap Icon per type via the optional yiirocks/svg-inline-bootstrap sibling, rendering silently without one when it isn't installed
Bootstrap's own JS
Registers a small show-script through the view (at end of body, after Bootstrap's bundle regardless of load order) that calls
bootstrap.Toast's own API, the only JS this package shipsOptions
delay array
['success' => 4000, 'error' => null, 'warning' => 6000, 'info' => 4000]Milliseconds before a toast auto-hides, keyed by type; null leaves it up until dismissed manually, the default for error.
icons array
['success' => 'check-circle-fill', 'error' => 'exclamation-octagon-fill', 'warning' => 'exclamation-triangle-fill', 'info' => 'info-circle-fill']Bootstrap Icon name keyed by type (requires yiirocks/svg-inline-bootstrap; renders without an icon if it is not installed); null disables that type's icon.
position string
'top-0 end-0'Space-separated Bootstrap position utility classes for the toast container.
Example
use YiiRocks\ToastBootstrap5\ToastType;
$this->toast->add(ToastType::ERROR, 'Something went wrong.');