PHPackages                             diecoding/yii2-toastr - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Mail &amp; Notifications](/categories/mail)
4. /
5. diecoding/yii2-toastr

ActiveLibrary[Mail &amp; Notifications](/categories/mail)

diecoding/yii2-toastr
=====================

Simple flash toastr notifications for Yii2

1.5.0(10mo ago)1328.8k↓47.1%2MITPHPPHP &gt;=7.4.0CI passing

Since Sep 25Pushed 10mo ago2 watchersCompare

[ Source](https://github.com/wanforge/yii2-toastr)[ Packagist](https://packagist.org/packages/diecoding/yii2-toastr)[ GitHub Sponsors](https://github.com/wanforge)[ Fund](https://ko-fi.com/wanforge)[ RSS](/packages/diecoding-yii2-toastr/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (6)Versions (19)Used By (0)

Yii2 Toastr
===========

[](#yii2-toastr)

Simple flash toastr notifications for Yii2

[![Latest Stable Version](https://camo.githubusercontent.com/9239532db4bafc81b3bf0ef2bf0b2cdcfec2f2d8aa327dda1b357f44e8537c06/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f646965636f64696e672f796969322d746f617374723f6c6162656c3d737461626c65)](https://packagist.org/packages/diecoding/yii2-toastr)[![PHP Version Require](https://camo.githubusercontent.com/6bce9e37fa2511c151c6ee1e8991ec8baa41dc5544eb74b72bf993f8fb6a25bb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646570656e64656e63792d762f646965636f64696e672f796969322d746f617374722f7068703f636f6c6f723d366637336136)](https://packagist.org/packages/diecoding/yii2-toastr)[![Total Downloads](https://camo.githubusercontent.com/8d64b00ac5e9d247d42db06a3a93990bf294746ffbc6013d795f587e2b7a3365/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f646965636f64696e672f796969322d746f61737472)](https://packagist.org/packages/diecoding/yii2-toastr)[![License](https://camo.githubusercontent.com/669b03b3380909da733e195fc4cd877350c5787156f49cf5c2fa6ebf568408de/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f77616e666f7267652f796969322d746f61737472)](https://github.com/wanforge/yii2-toastr)

[![Tests](https://github.com/wanforge/yii2-toastr/actions/workflows/tests.yml/badge.svg)](https://github.com/wanforge/yii2-toastr/actions/workflows/tests.yml)[![Coverage Status](https://camo.githubusercontent.com/d4a47658af1bf9d162f388d3b4300f2b335d311de72450ba8a0f764435d8a1a9/68747470733a2f2f636f6465636f762e696f2f67682f77616e666f7267652f796969322d746f617374722f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/wanforge/yii2-toastr)[![PHPStan Level](https://camo.githubusercontent.com/0729e562e10fac943b16dbb271b4af26488f779a33fc82cc3eef1e37a432c0b4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d6c6576656c253230352d627269676874677265656e2e737667)](https://github.com/wanforge/yii2-toastr/actions/workflows/tests.yml)[![PHP CS Fixer](https://camo.githubusercontent.com/38e614aea1a6f3fc8b28e94381eea217ddf872d67b03f03ad512ecdda6ff04f2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f504850253230435325323046697865722d5053522d2d31322d627269676874677265656e2e737667)](https://github.com/wanforge/yii2-toastr/actions/workflows/tests.yml)

> Yii2 Toastr uses [Toastr](https://codeseven.github.io/toastr/) library
> **Demo**:

Table of Contents
-----------------

[](#table-of-contents)

- [Yii2 Toastr](#yii2-toastr)
    - [Table of Contents](#table-of-contents)
    - [Installation](#installation)
    - [Dependencies](#dependencies)
    - [Usage](#usage)
        - [Layouts/Views](#layoutsviews)
            - [Basic Usage](#basic-usage)
            - [Advanced Configuration](#advanced-configuration)
        - [Controllers](#controllers)
            - [Simple Flash Messages](#simple-flash-messages)
            - [Multiple Messages](#multiple-messages)
            - [Messages with Titles (&lt; v1.4.0)](#messages-with-titles--v140)
            - [Advanced Usage with Custom Options (≥ v1.4.0)](#advanced-usage-with-custom-options--v140)
            - [Complex Example with Multiple Messages](#complex-example-with-multiple-messages)
    - [Testing](#testing)
    - [Code Quality](#code-quality)
    - [Contributing](#contributing)
    - [License](#license)

Installation
------------

[](#installation)

Install via [Composer](https://getcomposer.org):

```
composer require diecoding/yii2-toastr "^1.0"
```

Or add to your `composer.json`:

```
{
    "require": {
        "diecoding/yii2-toastr": "^1.0"
    }
}
```

Dependencies
------------

[](#dependencies)

- PHP 7.4+
- [yiisoft/yii2](https://github.com/yiisoft/yii2) (≥2.0.14)
- [npm-asset/toastr](https://asset-packagist.org/package/npm-asset/toastr)

Usage
-----

[](#usage)

### Layouts/Views

[](#layoutsviews)

Add `ToastrFlash` widget to your layout file (e.g., `views/layouts/main.php`):

#### Basic Usage

[](#basic-usage)

```
use diecoding\toastr\ToastrFlash;

ToastrFlash::widget();
```

#### Advanced Configuration

[](#advanced-configuration)

```
use diecoding\toastr\ToastrFlash;

ToastrFlash::widget([
    "typeDefault"       => ToastrFlash::TYPE_INFO,            // (string) default `ToastrFlash::TYPE_INFO`
    "titleDefault"      => "",                                // (string) default `""`
    "messageDefault"    => "",                                // (string) default `""`
    "closeButton"       => false,                             // (bool) default `false`
    "debug"             => false,                             // (bool) default `false`
    "newestOnTop"       => true,                              // (bool) default `true`
    "progressBar"       => true,                              // (bool) default `true`
    "positionClass"     => ToastrFlash::POSITION_TOP_RIGHT,   // (string) default `ToastrFlash::POSITION_TOP_RIGHT`
    "preventDuplicates" => true,                              // (bool) default `true`
    "showDuration"      => 300,                               // (int|null) default `300` in `ms`, `null` for skip
    "hideDuration"      => 1000,                              // (int|null) default `1000` in `ms`, `null` for skip
    "timeOut"           => 5000,                              // (int|null) default `5000` in `ms`, `null` for skip
    "extendedTimeOut"   => 1000,                              // (int|null) default `1000` in `ms`, `null` for skip
    "showEasing"        => "swing",                           // (string) default `swing`, `swing` and `linear` are built into jQuery
    "hideEasing"        => "swing",                           // (string) default `swing`, `swing` and `linear` are built into jQuery
    "showMethod"        => "slideDown",                       // (string) default `slideDown`, `fadeIn`, `slideDown`, and `show` are built into jQuery
    "hideMethod"        => "slideUp",                         // (string) default `slideUp`, `hide`, `fadeOut` and `slideUp` are built into jQuery
    "tapToDismiss"      => true,                              // (bool) default `true`
    "escapeHtml"        => true,                              // (bool) default `true`
    "rtl"               => false,                             // (bool) default `false`
    "skipCoreAssets"    => false,                             // (bool) default `false`, `true` if use custom or external toastr assets
    "options"           => [],                                // (array) default `[]`, Custom Toastr options and override default options
]);
```

### Controllers

[](#controllers)

Use the standard Yii2 flash message system:

#### Simple Flash Messages

[](#simple-flash-messages)

```
// Single message
Yii::$app->session->setFlash('error', 'Something went wrong!');
Yii::$app->session->setFlash('success', 'Operation completed successfully!');
Yii::$app->session->setFlash('info', 'Information message');
Yii::$app->session->setFlash('warning', 'Warning message');
```

#### Multiple Messages

[](#multiple-messages)

```
Yii::$app->session->setFlash('error', [
    'Message 1',
    'Message 2',
    'Message 3'
]);
```

#### Messages with Titles (&lt; v1.4.0)

[](#messages-with-titles--v140)

```
Yii::$app->session->setFlash('error', [
    ['Title', 'Message']
]);

// Multiple messages with titles
Yii::$app->session->setFlash('error', [
    ['Title 1', 'Message 1'],
    ['Title 2', 'Message 2'],
    ['Title 3', 'Message 3']
]);
```

#### Advanced Usage with Custom Options (≥ v1.4.0)

[](#advanced-usage-with-custom-options--v140)

```
// Array format
Yii::$app->session->setFlash('error', [
    ['Title', 'Message', ['timeOut' => 10000]]
]);

// Associative array format
Yii::$app->session->setFlash('error', [
    [
        'title' => 'Custom Title',
        'message' => 'Custom message',
        'options' => [
            'progressBar' => true,
            'timeOut' => 5000,
            'hideDuration' => 1000
        ]
    ]
]);
```

#### Complex Example with Multiple Messages

[](#complex-example-with-multiple-messages)

```
Yii::$app->session->setFlash('info', [
    [
        'title' => 'Step 1 Complete',
        'message' => 'Data validation passed',
        'options' => ['progressBar' => true, 'timeOut' => 5000]
    ],
    [
        'title' => 'Step 2 Complete',
        'message' => 'Data saved successfully',
        'options' => ['progressBar' => false, 'timeOut' => 3000]
    ],
    ['Simple message without custom options']
]);
```

Testing
-------

[](#testing)

Run the test suite using [PHPUnit](https://phpunit.de/):

```
# Install dependencies
composer install

# Run tests
composer test

# Run tests with coverage (requires PCOV or Xdebug)
composer test:coverage

# Generate HTML coverage report
composer test:coverage-html
```

The test suite covers:

- ✅ **ToastrBase** - Base widget functionality and constants
- ✅ **Toastr** - Main notification widget properties and methods
- ✅ **ToastrFlash** - Flash message integration
- ✅ **ToastrAsset** - Asset bundle configuration

**Coverage Requirements:**

- Target: &gt;80% code coverage
- Supports PHP 7.4, 8.0, 8.1, 8.2, 8.3
- Automated testing via GitHub Actions

Code Quality
------------

[](#code-quality)

This project maintains high standards through automated quality checks:

- **PHP CodeSniffer** - PSR-12 coding standards
- **PHP CS Fixer** - Modern PHP code formatting
- **PHPStan** - Static analysis (level 5)

```
# Run all quality checks
composer quality

# Individual commands
composer cs           # Check code style
composer cs:fix       # Auto-fix code style
composer phpstan      # Run static analysis
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please follow these steps:

1. **Fork** the repository
2. **Create** a feature branch (`git checkout -b feature/amazing-feature`)
3. **Make** your changes
4. **Run** quality checks (`composer quality`)
5. **Run** tests (`composer test`)
6. **Commit** your changes (`git commit -am 'Add amazing feature'`)
7. **Push** to the branch (`git push origin feature/amazing-feature`)
8. **Open** a Pull Request

**Requirements:**

- Write tests for new features
- Follow PSR-12 coding standards
- Ensure all quality checks pass
- Update documentation as needed

License
-------

[](#license)

This package is open-source software licensed under the [MIT License](LICENSE).

---

**Author**: [Sugeng Sulistiyawan](https://github.com/wanforge)
**Copyright**: © 2018-2025 Sugeng Sulistiyawan

Built with ❤️ for the Yii2 community.

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance55

Moderate activity, may be stable

Popularity35

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 97.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~146 days

Recently: every ~112 days

Total

18

Last Release

303d ago

PHP version history (3 changes)v1.0.3PHP &gt;=5.6.0

v1.0.4PHP &gt;=7.0

v1.2.0PHP &gt;=7.4.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/a5fa8faeecf1f3d0da2d981ae5e4238e1590a7897b14b890663a0c49ef03e87a?d=identicon)[diecoding](/maintainers/diecoding)

---

Top Contributors

[![wanforge](https://avatars.githubusercontent.com/u/16300077?v=4)](https://github.com/wanforge "wanforge (122 commits)")[![scrutinizer-auto-fixer](https://avatars.githubusercontent.com/u/6253494?v=4)](https://github.com/scrutinizer-auto-fixer "scrutinizer-auto-fixer (3 commits)")

---

Tags

flashphptoastrwidgetyii2yii2-extensionnotificationjquerysessionyii2widgetflashtoastr

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/diecoding-yii2-toastr/health.svg)

```
[![Health](https://phpackages.com/badges/diecoding-yii2-toastr/health.svg)](https://phpackages.com/packages/diecoding-yii2-toastr)
```

###  Alternatives

[kartik-v/yii2-widget-alert

A widget to generate alert based notifications using bootstrap-alert plugin (sub repo split from yii2-widgets)

284.1M24](/packages/kartik-v-yii2-widget-alert)[loveorigami/yii2-notification-wrapper

This module for renders a message from session flash (with ajax, pjax support and etc.)

77199.7k5](/packages/loveorigami-yii2-notification-wrapper)[kartik-v/yii2-widget-growl

A widget to generate growl based notifications using bootstrap-growl plugin (sub repo split from yii2-widgets)

384.2M14](/packages/kartik-v-yii2-widget-growl)[odaialali/yii2-toastr

This is the Toastr extension for Yii 2. It encapsulates Toastr plugin in terms of Yii widgets, and makes ajax notification easy to implement.

1486.3k](/packages/odaialali-yii2-toastr)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
