ruturajmaniyar/yii2-flash-toastr

使用jQuery和yii2实现的Toastr闪存通知

dev-master 2020-04-28 20:34 UTC

This package is auto-updated.

Last update: 2024-09-29 05:28:33 UTC


README

使用jQuery和yii2实现的Toastr闪存通知

GitHub release Packagist

当前版本

v1.0 @稳定 @预发布

安装

通过以下方式安装此扩展:通过 composer.

运行以下命令之一:

php composer.phar require --prefer-dist ruturajmaniyar/yii2-flash-toastr: "dev-master"

composer require --prefer-dist ruturajmaniyar/yii2-flash-toastr: "dev-master"

或者

"ruturajmaniyar/yii2-flash-toastr": "dev-master"

将以下内容添加到您的 composer.json 文件的require部分。

用法

扩展安装完成后,只需在您的代码中通过以下方式使用它:

<?php if (Yii::$app->session->hasFlash('success')): ?>
    <?= ToastrFlashMessage::widget([
        'type' => 'success',
        'title' => 'Success',
        'message' => Yii::$app->session->getFlash('success')
    ]); ?>
<?php endif; ?>

<?php if (Yii::$app->session->hasFlash('error')): ?>
    <?= ToastrFlashMessage::widget([
        'type' => 'error',
        'title' => 'Error',
        'message' => Yii::$app->session->getFlash('error')
    ]); ?>
<?php endif; ?>

您还可以使用以下代码:

<?= ToastrFlashMessageSession::widget() ?>

使用以上代码,扩展将根据您的会话消息动态设置toastr消息

其他选项

'options' => [
        "closeButton" => true,
        "newestOnTop" => true,
        "progressBar" => true,
        "positionClass" => ToastrFlashMessage::POSITION_TOP_RIGHT,
        "showDuration" => "300", 
        "hideDuration" => "1000",
        "timeOut" => "5000",
        "extendedTimeOut" => "1000",
        "showEasing" => "swing",
        "hideEasing" => "linear",
        "closeEasing" => "linear",
        "showMethod" => "slideDown",
        "hideMethod" => "slideUp",
        "closeMethod" => "slideUp"
    ]
Toast位置选项
POSITION_TOP_RIGHT = 'toast-top-right';
POSITION_TOP_LEFT = 'toast-top-left';
POSITION_TOP_CENTER = 'toast-top-center';
POSITION_TOP_FULL_WIDTH = 'toast-top-full-width';

POSITION_BOTTOM_RIGHT = 'toast-bottom-right';
POSITION_BOTTOM_LEFT = 'toast-bottom-left';
POSITION_BOTTOM_CENTER = 'toast-bottom-center';
POSITION_BOTTOM_FULL_WIDTH = 'toast-bottom-full-width';
演示