seyfer / zend-flashmessenger-toastr
带有 Toastr 集成的 Zend Framework 3 flashmessenger 模块
Requires
- php: ^5.6 || ^7.0
- seyfer/phpflashmessages: ~1.0.1
- zendframework/zend-mvc: ~3.0.4
This package is auto-updated.
Last update: 2020-01-10 16:08:20 UTC
README
动机
-
我在官方 ZF3 FlashMessenger 模块中遇到了问题,并决定编写自己的独立模块。作为闪存消息的基础,我得到了一个简单的纯 PHP 库。 https://github.com/plasticbrain/PhpFlashMessages
-
我想集成 Toastr js 库以获得更好的闪存消息 UI,并使其能够轻松在 Toastr 视图和标准 Bootstrap 视图之间切换。 https://codeseven.github.io/toastr/
如果您想使用标准的 ZF3 Flashmessenger,还有一个可用的模块。 https://github.com/jenzri-nizar/zf3-flashmessenger
以下是使用 Toastr 视图时的样子。
以下是 Bootstrap 视图。
安装
composer require seyfer/zend-flashmessenger-toastr
然后,将模块添加到您的 config/modules.config.php
'modules' => [ '...', 'Seyfer\Zend\Flashmessenger' ],
您可以通过在 module.config.php 中使用此配置来切换 Toastr 库文件的来源
'toastr' => [ //cdn or assets 'source' => 'cdn', ],
如何使用它
使用提供的插件在控制器中添加消息。
<?php $this->msg()->addSuccessMessage('test'); $this->msg()->addErrorMessage('test'); $this->msg()->addInfoMessage('test'); $this->msg()->addWarningMessage('test');
如果您想输出 Toastr 风格的消息,只需在 layout.phtml 中使用提供的视图辅助方法。同时,您还需要包含 inlineSript 辅助方法。
<?php $this->msg()->renderToastr(); ?> <?php echo $this->inlineScript() ?>
对于标准的 Bootstrap 视图,使用另一种方法。
<?php $this->msg()->renderToastr(); ?> <?php echo $this->inlineScript() ?>
就是这样!
请随时贡献并发送 pull 请求。

