manuelj555 / ajax-flash-bundle
Symfony ManuelAjaxFlashBundle
1.0.1
2014-10-06 18:56 UTC
Requires
- symfony/symfony: ~2.3
This package is auto-updated.
Last update: 2024-09-22 02:54:22 UTC
README
此包允许通过JavaScript在ajax请求中处理闪存。需要jQuery。
安装
添加到composer.json
{ "require": { "manuelj555/ajax-flash-bundle": "1.0.*@dev" } }
执行composer update。
配置
注册包
<?php // app/AppKernel.php public function registerBundles() { return array( // ... new Manuelj555\Bundle\AjaxFlashBundle\ManuelAjaxFlashBundle(), // ... ); }
在config.yml中(所有配置均为可选)
manuel_ajax_flash: auto_assets: pnotify: ~ # sticky: ~ mapping: # success: # title: Información # icon: my-icon # info: # title: Información
auto_assets
自动将javascript和css添加到html内容中。您可以选择要使用的插件,可用的选项有
- pnotify (http://sciactive.com/pnotify/)
- sticky (http://danielraftery.com/read/Sticky-A-super-simple-notification-system-for-jQuery)
mapping
允许为每个设置的映射类型设置标题、图标和类型,用于javascript。
示例
manuel_ajax_flash: mapping: success: type: success title: Información icon: my-icon info: type: info title: Información error: type: danger title: Error
手动资产安装
如果您未启用auto_assets配置,您可以使用位于包中的twig视图
- ManuelAjaxFlashBundle::pnotify.html.twig 或
- ManuelAjaxFlashBundle::sticky.html.twig
使用示例
{% use 'ManuelAjaxFlashBundle::pnotify.html.twig' %} {#{% use 'ManuelAjaxFlashBundle::sticky.html.twig' %}#} <!DOCTYPE html> <html> <head> ... {{ block('ajax_flash_css') }} </head> <body> ... {{ block('ajax_flash_js') }} {{ block('ajax_flash_plugin') }} </body> </html>
JavaScript插件
使用方法
$.ajaxFlash('*', function (message, type, title, icon) { //call on all flash types. this function is called for each flash message //the message parameter is a string }); $.ajaxFlash('success info', function (message, type, title, icon) { //call on success and info flash types. this function is called for each flash message //the message parameter is a string }); $.ajaxFlash('error', function (message, type, title, icon) { //call on error flash type. this function is called for each flash message //the message parameter is a string }); // Working with array messages: $.ajaxFlash(function (messages, type, title, icon) { //call in all flash types, this function is called one time for each message type. //the messages parameter is an array. }); $.ajaxFlash(function (messages, type, title, icon) { //call success and info flash types, this function is called one time for each message type. //the messages parameter is an array. }, 'success info');