tegimus/php-izitoast
最新稳定版本:v1.0
Composer 安装命令:
composer require tegimus/php-izitoast
包简介
A simple php wrapper for the iziToast javascript library
README 文档
README
A simple php wrapper for the iziToast javascript library
Requirements
PHP 7 or greater
Installation
Using Composer
composer require tegimus/php-izitoast
Manual
You can also use the package class file src/Toast.php directly in your project since it has no other dependencies.
Adding the iziToast library files
Download the latest iziToast javascript and stylesheet files from iziToast github repository.
Add the iziToast css and js files to your html.
<html> <head> ... <link rel="stylesheet" type="text/css" href="/path/to/css/iziToast.min.css"> ... </head> <body> ... <script type="text/javascript" src="/path/to/js/iziToast.min.js"></script> </body> </html>
Basic Usage
Creating the Toast object
Using constructor
use Tegimus\IziToast\Toast; $toast = new Toast();
Or using the static make() method
$toast = Toast::make();
Constructor Parameters
The constructor can optionally receive message, title, type and options parameters.
$title = 'Test'; $message = 'My sample message'; $type = Toast::TYPE_SUCCESS; $options = ['progressBar' => false]; $toast = new Toast($message); //or $toast = Toast:make($message, $title, $type, $options);
Display the message
To show the toast message, simply use the render() function on the Toast object inside javascript in your HTML.
<script> <?php $toast->render() ?> </script>
Or in string contexts you can simply echo the Toast object
<script> <?= $toast ?> </script>
Customizing
Message types
You can set the type of the message by calling type() method on the Toast object.
$toast->type(Toast::TYPE_ERROR);
Message options
By default, the Toast object will have the below options set.
'closeOnEscape' : true
'closeOnClick' : true
'position' : 'topCenter'
'progressBar' : false
'transitionIn' : 'bounceInLeft'
To override an option or to add a new one, use the option() method
$toast->option('timeout', false);
Or specify multiple options at once
$toast->mergeOptions([ 'position' => 'bottomRight', 'timeout' => 6000, 'pauseOnHover' => false, ]);
Or replace all options with the given array. All existing options will be cleared including message and title.
$toast->options([ 'message' => 'Sample message', 'title' => 'Replace', 'position' => 'bottomRight', 'timeout' => 6000, 'pauseOnHover' => false, ]);
To clear an option use the clear() method. All options will be cleared if no parameter is specified.
//clear 'position' option $toast->clear('position'); //clear all options $toast->clear();
All types and options available for the iziToast library are documented here.
Extending the Toast class
Read here to know more about extending and customizing the Toast class
统计信息
- 总下载量: 1.33k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0
- 更新时间: 2018-08-05