bestmodules/alertify-bundle
Composer 安装命令:
composer require bestmodules/alertify-bundle
包简介
Symfony AlertifyBundle
关键字:
README 文档
README
What is the point ?
This bundle allows you to easily harmonize alerts and others notifications. Declare in the config (or just use the default configuration) and dispatch alerts with the following libraries (or your own):
- TwitterBootstrap (http://twitter.github.com/bootstrap/javascript.html#modals) or
- Noty (http://needim.github.com/noty/) or
- Toastr (https://github.com/CodeSeven/toastr)
Installation
First, require it thanks to composer:
composer.phar require bestmodules/alertify-bundle:dev-master
Add it in your AppKernel.php:
public function registerBundles() {
$bundles = array(
[...]
new AppVentus\AlertifyBundle\AvAlertifyBundle(),
[...]
Then, just publish your assets, annnnnnd it's done !
Configuration
To define the default configuration of your alerts, you can add the following lines in your config.yml :
av_alertify: contexts: front: engine: "toastr" \#Could be noty, modal, toastr, alert or your own layout: "top-right" \#Is relative according to the selected engine translationDomain: "messages" \#Where do you want to store the translation strings admin: engine: "myOwnSystem" layout: "bottomRight" translationDomain: "messages"
By default, even if you do not declare any context, Alertify setup default values. You can override these settings easily like this:
av_alertify: default: context: app \#default: front engine: noty \#default: toastr layout: bottomLeft \#default: top-right translationDomain: messages \#default: flash contexts: ...
Usage
It's easy to use, just follow the following:
Add this block at the end of your twig layout:
{% block alertify %}
{{ app.session|alertify|raw }}
{% endblock %}
Now, anywhere, you can put your alert in the flash session and enjoy. (DEPRECATED)
$this->get('session')->getFlashBag()->add('success', 'ok');
$this->get('session')->getFlashBag()->add('warning', array('body' => 'ok');
$this->get('session')->getFlashBag()->add('warning', array('body' => 'ok', 'context' => 'front');
You can publish your message to session flashbag by using service "alertify". For instance:
$this->container->get('alertify')->success([ 'engine' => 'alert', 'title' => "Password successfully changed", ]);
If you have two contexts in your application (front and back for example), I advice you to override these functions in your controller in each side to pass automatic context like this:
class BaseFrontController { /** * congrat user through flashbag : all happened successfully * Will automatically inject context * @param string $content */ public function congrat($content) { $content = array('body' => $content, 'context' => 'front'); $this->get('av.shortcuts')->congrat($content); } }
Display alerts with a custom library
AvAlertify comes with some libraries to ease use but it's free to you to use custom Library (feel free to make a Pull request, your library could interest community :). You just have to follow these steps :
av_alertify: contexts: front: engine: "myOwnSystem" layout: "bottomRight" \#it's up to your library translationDomain: "messages"
Then just override app/Resources/AvAlertifyBundle/views/Modal/myOwnSystem.html.twig and add the alert initialization.
Options
Modal
To call a modal box, just use a flash named 'modal':
$this->get('session')->getFlashBag()->add("success", array('engine' => 'modal', 'title' => "Wow", 'button_class' => "btn btn-primary btn-large", "body"=> "<div>Some info</div>"));
as you see, you can pass some arguments tu customize the modal, availables ones are:
title:
(html) string
button-class:
you con specify classes to customize your button
body:
html string
hasHeader:
boolean (default = true)
hasFooter:
boolean (default = true)
deleteIcon:
string : icon-class (for example: "fa fa-times")
id:
string : (default: "alertify-modal")
Callback type
There is a final type of Alert you can call, the callback Callbach allow you to call any action in you project, thats awesome if you want put dynamic content in your alery. To work, the called action have to render a view. It's very usefull to include a form in a modal for exemple.
$this->get('session')
->getFlashBag()
->set('callback', array(
'engine' => 'modal',
'title' => 'Wow',
'action' => 'AcmeBundle:Default:hello',
'button_class' => 'btn btn-primary btn-large',
'body' => '<p>Yeah that's crazy !</p>'
)
);
This type is very simple to use, just call the callback alery, and in the options define "type" with the final alert you want, the action with the action you want call, and other options specific to the alery you choose.
Ajax mode
We told you to add the alertify filter in your layout. This is great but what if you want to use ajax in your application ?
Actually, this library is not really made for it but you can simply add this part of code to trigger alerts in your new ajax content :
{% if app.request.isXmlHttpRequest %}
{{ app.session|alertify|raw }}
{% endif %}
Confirm modal
After a link's clic or form's submission, we sometimes want to prompt the user to be sure he understood what he did. You can make it as a simply way by following the doc here : (https://github.com/AppVentus/AvAlertifyBundle/blob/master/README_Confirm.md)
bestmodules/alertify-bundle 适用场景与选型建议
bestmodules/alertify-bundle 是一款 基于 CSS 开发的 Composer 扩展包,目前已累计 120 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 03 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「bootstrap」 「alert」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 bestmodules/alertify-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bestmodules/alertify-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 bestmodules/alertify-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Views for the package MedicOneSystems Livewire Datatables with Bootstrap 4
bootstrap select field module implementing http://silviomoreto.github.io/bootstrap-select/
Selectize Theme for Bootstrap 4
Yii bot for sending messages (alerts) to Slack
A simple PHP package to show Sweet Alerts with the Laravel Framework
Cross browser time implementation using CSS and JQuery. Compatible with Twitter Bootstrap
统计信息
- 总下载量: 120
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 22
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-01