PHPackages                             yii2mod/yii2-sweet-alert - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. yii2mod/yii2-sweet-alert

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

yii2mod/yii2-sweet-alert
========================

Alert widget based on SweetAlert extension {@link http://tristanedwards.me/sweetalert)

1.3(8y ago)43154.0k↓16.1%16[4 issues](https://github.com/yii2mod/yii2-sweet-alert/issues)2MITPHPPHP &gt;=5.5CI failing

Since Sep 24Pushed 8y ago6 watchersCompare

[ Source](https://github.com/yii2mod/yii2-sweet-alert)[ Packagist](https://packagist.org/packages/yii2mod/yii2-sweet-alert)[ RSS](/packages/yii2mod-yii2-sweet-alert/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (5)Versions (6)Used By (2)

 [ ![](https://avatars0.githubusercontent.com/u/993323) ](https://github.com/yiisoft)

Yii2 Alert Widget
=================

[](#yii2-alert-widget)

Alert widget based on [SweetAlert](http://t4t5.github.io/sweetalert/)

[![Latest Stable Version](https://camo.githubusercontent.com/09a67360f50861dc9776086fffc93da86289dc496ec4abe9717f28dbaa949616/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d73776565742d616c6572742f762f737461626c65)](https://packagist.org/packages/yii2mod/yii2-sweet-alert) [![Total Downloads](https://camo.githubusercontent.com/d3fddfdd28615e123e08b55092dbaca7099caae5b66837294b789cc519fcc221/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d73776565742d616c6572742f646f776e6c6f616473)](https://packagist.org/packages/yii2mod/yii2-sweet-alert) [![License](https://camo.githubusercontent.com/0407a731f90b042063372ab16f1def190183ecfcca41d3312c0896fe9b2c457e/68747470733a2f2f706f7365722e707567782e6f72672f796969326d6f642f796969322d73776565742d616c6572742f6c6963656e7365)](https://packagist.org/packages/yii2mod/yii2-sweet-alert)[![Build Status](https://camo.githubusercontent.com/a2c879c419a5b1d9ee5f1d107be2ee7cf566156d79e9a01bcd1efafebb106fa9/68747470733a2f2f7472617669732d63692e6f72672f796969326d6f642f796969322d73776565742d616c6572742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/yii2mod/yii2-sweet-alert)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
php composer.phar require --prefer-dist yii2mod/yii2-sweet-alert "*"

```

or add

```
"yii2mod/yii2-sweet-alert": "*"

```

to the require section of your composer.json.

Usage
-----

[](#usage)

**For render the message from session flash you can use the following code:**

1. Set the message in your action, for example:

```
Yii::$app->session->setFlash('success', 'This is the message');
```

2. Simply add widget to your page as follows:

```
echo Alert::widget();
```

**For render the custom message you can use the following code:**

```
// A replacement for the "prompt" function

echo \yii2mod\alert\Alert::widget([
    'useSessionFlash' => false,
    'options' => [
        'timer' => null,
        'type' => \yii2mod\alert\Alert::TYPE_INPUT,
        'title' => 'An input!',
        'text' => "Write something interesting",
        'confirmButtonText' => "Yes, delete it!",
        'closeOnConfirm' => false,
        'showCancelButton' => true,
        'animation' => "slide-from-top",
        'inputPlaceholder' => "Write something"
    ],
    'callback' => new \yii\web\JsExpression(' function(inputValue) {
                if (inputValue === false) return false;
                if (inputValue === "") {
                    swal.showInputError("You need to write something!");
                    return false;
                }
                swal("Nice!", "You wrote: " + inputValue, "success");
    }')
]);
```

**You can also change the theme of SweetAlert!**

To change the theme, you can configure the assetManager array in your application configuration:

```
// twitter theme

'assetManager' => [
    'bundles' => [
        'yii2mod\alert\AlertAsset' => [
            'css' => [
                'dist/sweetalert.css',
                'themes/twitter/twitter.css',
            ]
        ],
    ],
]
```

**You can override the Yii2 default data-confirm popup by the following code:**

The basics are to include the asset, then add this JS:

```
/**
 * Override the default yii confirm dialog. This function is
 * called by yii when a confirmation is requested.
 *
 * @param message the message to display
 * @param okCallback triggered when confirmation is true
 * @param cancelCallback callback triggered when cancelled
 */
yii.confirm = function (message, okCallback, cancelCallback) {
    swal({
        title: message,
        type: 'warning',
        showCancelButton: true,
        closeOnConfirm: true,
        allowOutsideClick: true
    }, okCallback);
};
```

Alert Options
-------------

[](#alert-options)

You can find them on the [options page](http://t4t5.github.io/sweetalert/)

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance18

Infrequent updates — may be unmaintained

Popularity45

Moderate usage in the ecosystem

Community20

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% 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 ~179 days

Total

5

Last Release

3171d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a53a15e1548ce60ee92591e71492a39eaaecfc88eaa1a9d7f353d5c910381de?d=identicon)[disem](/maintainers/disem)

---

Top Contributors

[![dmitry-semenov](https://avatars.githubusercontent.com/u/17027799?v=4)](https://github.com/dmitry-semenov "dmitry-semenov (2 commits)")[![renatocassino](https://avatars.githubusercontent.com/u/5348316?v=4)](https://github.com/renatocassino "renatocassino (1 commits)")

---

Tags

yii2yii2-alertyii2-alert-widgetyii2-extensionyii2yii2 alertyii2 sweet alert

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/yii2mod-yii2-sweet-alert/health.svg)

```
[![Health](https://phpackages.com/badges/yii2mod-yii2-sweet-alert/health.svg)](https://phpackages.com/packages/yii2mod-yii2-sweet-alert)
```

###  Alternatives

[asinfotrack/yii2-toolbox

Yii2-Toolbox is a collection of useful helpers, widgets etc. extending the basic functionality of Yii2

1230.5k5](/packages/asinfotrack-yii2-toolbox)

PHPackages © 2026

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