languaojs/viper-flasher
最新稳定版本:v0.1.0
Composer 安装命令:
composer require languaojs/viper-flasher
包简介
A SweetAlert2 Toast wrapper for ViperPHP and other PHP frameworks.
README 文档
README
A lightweight PHP library to handle flash messages using SweetAlert2 toasts. Originally built for the ViperPHP framework, but compatible with any PHP project.
🚀 Installation
Install the package via Composer:
composer require languaojs/viper-flasher
If you are using ViperPHP, run the command above in the root folder of your project.
📋 Requirements
This library requires jQuery and SweetAlert2 to be present in your HTML template. Add these CDNs to your header or footer:
<!-- jQuery --> <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script> <!-- SweetAlert2 --> <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
If you are using ViperPHP, you will configure these assets in your controller (see ViperPHP documentation in my GitHub repo).
🛠 Usage
1. Initialize Session
Ensure that session_start() is called at the beginning of your application. With ViperPHP, you do not need to do this.
2. Set a Flash Message
Use the setFlash method in your Controller or logic:
use Viper\Flasher\Flasher; // Parameters: type (success, error, info, warning), message Flasher::setFlash('success', 'Data saved successfully!');
3. Fire the Flash Message
Call the flash() method in your view (ideally at the bottom of the body):
<?php use Viper\Flasher\Flasher; Flasher::flash(); ?>
🎨 Toast Configuration
By default, this library uses a SweetAlert2 Toast with the following settings:
- Position: Top-end
- Timer: 5000ms
- Progress Bar: Enabled
- Confirm Button: Disabled
📜 License
This project is licensed under the MIT License.
Created by Zainurrahman
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-31