zunnu/cake-toastr
Composer 安装命令:
composer require zunnu/cake-toastr
包简介
A CakePHP plugin for integrating Toastr notifications.
README 文档
README
This package was created primarily for personal use. It allows you to easily integrate Toastr messages into your CakePHP application
Installing Using Composer
cd to the root of your app folder (where the composer.json file is) and run the following command:
composer require zunnu/cake-toastr
Then load the plugin by using CakePHP's console:
./bin/cake plugin load CakeToastr
Note the flash component does not need to be loaded but you need to have flash render in your layout.
<?= $this->Flash->render() ?>
Usage
Loading the Component
Load the component you will need to modify your src/Controller/AppController.php and load the toastr component in the initialize() function
$this->Flash = $this->loadComponent('CakeToastr.Toastr', ['alias' => 'Flash']);
Loading the Helper
Sure, you could load the view helper anywhere you like—like in a random controller or buried deep inside a view. But if you actually want things to work smoothly, and, you know, avoid a headache, just load it in the layout where it belongs. Because who doesn't love clean, maintainable code, right?
$this->loadHelper('CakeToastr.Toastr', ['progressBar' => true]);
See? Super simple. And if you're feeling extra fancy and want to tweak the options, go ahead and generate them from this magical place.
Using Flash Messages
From a controller, you can call it like a normal flash message:
$this->Flash->warning('This is a custom success message');
This simple setup allows you to start using Toastr notifications with default settings. If you'd like to customize the behavior, you can pass additional options.
Customizing Toastr Notifications
Using Callbacks
You can customize the behavior of Toastr notifications using JavaScript callbacks such as onShown, onShow, onHide, and onHidden. For example, if you want to execute custom JavaScript when a toast is fully displayed, you can use the onShown callback.
Here's how to use the onShown callback:
$this->loadHelper('CakeToastr.Toastr', [ 'positionClass' => 'toast-bottom-center', 'callbacks' => [ 'onShown' => 'function() { console.log("Toastr notification displayed"); }' ] ]);
This setup logs a message to the console when the toast is shown.
Injecting Custom CSS
You can also inject custom CSS to style your Toastr notifications. For instance, if you want to adjust the minimum width and position of your toast messages, you can pass custom CSS as follows:
$this->loadHelper('CakeToastr.Toastr', [ 'positionClass' => 'toast-bottom-center', 'customCss' => ' .toast-bottom-center { bottom: 8%; } .toast-bottom-center .toast { min-width: 600px; } ', 'callbacks' => [ 'onShown' => 'function() { console.log("Custom styles applied and Toastr notification shown"); }' ] ]);
This will ensure that the toast messages have a minimum width of 600px and are positioned 8% from the bottom of the screen.
Putting It All Together
Combine callbacks and custom CSS for a fully customized experience:
$this->loadHelper('CakeToastr.Toastr', [ 'positionClass' => 'toast-bottom-center', 'customCss' => ' .toast-bottom-center { bottom: 8%; } .toast-bottom-center .toast { min-width: 600px; } ', 'callbacks' => [ 'onShown' => 'function() { $(".toast-bottom-center .toast").css("background-color", "#333"); console.log("Custom background color applied and Toastr notification shown"); }' ] ]);
In this example, the toast background color is dynamically changed to a custom color when the toast is shown.
License
Licensed under The MIT License.
zunnu/cake-toastr 适用场景与选型建议
zunnu/cake-toastr 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 72 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 08 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 zunnu/cake-toastr 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 zunnu/cake-toastr 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 72
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-05