PHPackages                             aryelds/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. aryelds/yii2-sweet-alert

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

aryelds/yii2-sweet-alert
========================

A widget to flash sweet alert messages using SweetAlert plugin

3016.9k↓27.4%3PHP

Since May 12Pushed 8y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

yii2-sweet-alert
================

[](#yii2-sweet-alert)

Simple way to flash sweet alert messages to the screen. This widget is a wrapper by [SweetAlert Plugin](http://t4t5.github.io/sweetalert/)

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

[](#installation)

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

To install, either run

```
$ php composer.phar require aryelds/yii2-sweet-alert "@dev"

```

or add

```
"aryelds/yii2-sweet-alert": "@dev"

```

to the `require` section of your `composer.json` file.

Usage
-----

[](#usage)

### Basic Message

[](#basic-message)

```
use aryelds\sweetalert\SweetAlert;

echo SweetAlert::widget([
    'options' => [
        'title' => "Here's a message!"
    ]
]);
```

### A title with a text under

[](#a-title-with-a-text-under)

```
use aryelds\sweetalert\SweetAlert;

echo SweetAlert::widget([
    'options' => [
        'title' => "Here's a message!",
        'text' => "It's pretty, isn't it?"
    ]
]);
```

### Success message

[](#success-message)

```
use aryelds\sweetalert\SweetAlert;

echo SweetAlert::widget([
    'options' => [
        'title' => "Good Job!",
        'text' => "You clicked the button!",
        'type' => SweetAlert::TYPE_SUCCESS
    ]
]);
```

### Error message

[](#error-message)

```
use aryelds\sweetalert\SweetAlert;

echo SweetAlert::widget([
    'options' => [
        'title' => "Error!",
        'text' => "An error happened!",
        'type' => SweetAlert::TYPE_ERROR
    ]
]);
```

### A warning with "confirm" and "cancel" function

[](#a-warning-with-confirm-and-cancel-function)

```
use aryelds\sweetalert\SweetAlert;

echo SweetAlert::widget([
    'options' => [
        'title' => "Are you sure?",
        'text' => "You will not be able to recover this imaginary file!",
        'type' => SweetAlert::TYPE_WARNING,
        'showCancelButton' => true,
        'confirmButtonColor' => "#DD6B55",
        'confirmButtonText' => "Yes, delete it!",
        'cancelButtonText' => "No, cancel plx!",
        'closeOnConfirm' => false,
        'closeOnCancel' => false
    ],
    'callbackJs' => new \yii\web\JsExpression(' function(isConfirm) {
        if (isConfirm) {
            swal("Deleted!", "Your imaginary file has been deleted.", "success");
        } else {
            swal("Cancelled", "Your imaginary file is safe :)", "error");
        }
    }')
]);
```

### A replacement for the "prompt" function

[](#a-replacement-for-the-prompt-function)

```
use aryelds\sweetalert\SweetAlert;

echo SweetAlert::widget([
    'options' => [
        'title' => "An input!",
        'text' => "Write something interesting:",
        'type' => SweetAlert::TYPE_INPUT,
        'showCancelButton' => true,
        'closeOnConfirm' => false,
        'animation' => "slide-from-top",
        'inputPlaceholder' => "Write something"
    ],
    'callbackJs' => 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");
    }')
]);
```

### Html Message

[](#html-message)

```
use aryelds\sweetalert\SweetAlert;
use yii\bootstrap\Html;

echo SweetAlert::widget([
    'options' => [
        'title' => Html::tag('small', 'HTML Message!', ['style' => 'color: #00008B']),
        'text' => Html::tag('h2', 'Custom Message'),
        'type' => SweetAlert::TYPE_INFO,
        'html' => true
    ]
]);
```

### Using SweetAlert with flash messages

[](#using-sweetalert-with-flash-messages)

#### Controller Example

[](#controller-example)

```
public function actionPage() {
    $model = new SomeModel();

    Yii::$app->getSession()->setFlash('success', [
        'text' => 'My custom text',
        'title' => 'My custom title',
        'type' => 'success',
        'timer' => 3000,
        'showConfirmButton' => false
    ]);

    return $this->render('page', [
        'model' => $model,
    ]);
}

```

#### The View

[](#the-view)

```
use aryelds\sweetalert\SweetAlert;

foreach (Yii::$app->session->getAllFlashes() as $message) {
    echo SweetAlert::widget([
        'options' => [
            'title' => (!empty($message['title'])) ? Html::encode($message['title']) : 'Title Not Set!',
            'text' => (!empty($message['text'])) ? Html::encode($message['text']) : 'Text Not Set!',
            'type' => (!empty($message['type'])) ? $message['type'] : SweetAlert::TYPE_INFO,
            'timer' => (!empty($message['timer'])) ? $message['timer'] : 4000,
            'showConfirmButton' =>  (!empty($message['showConfirmButton'])) ? $message['showConfirmButton'] : true
        ]
    ]);
}
```

### Using themes

[](#using-themes)

#### You can select one of the following options:

[](#you-can-select-one-of-the-following-options)

```
SweetAlert::THEME_TWITTER
SweetAlert::THEME_GOOGLE
SweetAlert::THEME_FACEBOOK
```

#### Example:

[](#example)

```
use aryelds\sweetalert\SweetAlert;

echo SweetAlert::widget([
    'options' => [
        'title' => 'Themes!',
        'text' => 'Here\'s the Twitter theme for SweetAlert!',
        'confirmButtonText' => "Cool!",
        'animation' => 'slide-from-top',
        'theme' => SweetAlert::THEME_TWITTER
    ]
]);
```

For more options visit the plugin page
--------------------------------------

[](#for-more-options-visit-the-plugin-page)

[SweetAlert](http://t4t5.github.io/sweetalert/)

License
-------

[](#license)

**yii2-sweet-alert** is released under the BSD 3-Clause License. See the bundled `LICENSE.md` for details.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/abed5ea0a6b15d0dd9dc515387e7f4459151c8d461d3caecda54a7af3b6b685f?d=identicon)[Aryel Santos](/maintainers/Aryel%20Santos)

---

Top Contributors

[![aryelds](https://avatars.githubusercontent.com/u/8962452?v=4)](https://github.com/aryelds "aryelds (7 commits)")

### Embed Badge

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

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

###  Alternatives

[roomies/phonable

Gather insights and verify phone numbers from multiple third-party providers.

123.5k](/packages/roomies-phonable)

PHPackages © 2026

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