lrotherfield / notification-bundle
这是一个简单的通知包,用于创建带有javascript和css过渡效果的闪存和即时通知
dev-master
2013-05-14 19:15 UTC
Requires
- php: >=5.3.2
Requires (Dev)
- symfony/framework-bundle: >=2.1,<=2.2-dev
This package is not auto-updated.
Last update: 2024-09-14 13:50:21 UTC
README
#Notification Bundle
此包提供创建将用javascript渲染到用户的闪存通知和即时通知的方法。Symfony2已经有一个用于闪存消息的flashBag,此包在此基础上增加了使用humane.js的可定制javascript通知。
##安装说明
安装此包最简单的方法是使用composer。
将通知包作为依赖项添加到composer.json
{ "require":{ "lrotherfield/notification-bundle": "dev-master" }
使用composer更新依赖项
$ php composer.phar update
将通知包添加到AppKernal.php文件
class AppKernel extends Kernel { public function registerBundles() { $bundles = array( //... new LRotherfield\Bundle\NotificationBundle\LRotherfieldNotificationBundle(),
此包使用js和css文件,因此需要将其添加到config.yml中的assetic配置中
# Assetic Configuration assetic: #... bundles: [LRotherfieldNotificationBundle]
这样就安装完成了。
##简单使用
主要有两组功能,添加通知和渲染通知。
###添加通知
要添加通知,请使用add()
方法
// any class with access to the service container $this->container->get('lrotherfield.notify')->add("foo", array("message" => "bar"));
###渲染通知
Humane js和css文件需要放在head标签中,以便此类能够正常工作。在关闭head标签之前,运行twig函数notify_resources()
{{ notify_resources() }} </head>
有两个twig函数用于渲染通知,它们应该在关闭body标签之前调用
{{ notify_all() }} {# renders all notifications #} {{ notify_one("foo") }} {# renders all "foo" notifications like the one added in the above example #} </body>
可以在notify_all()
和notify_one()
中提供一个参数,以指定将消息附加为子元素的元素id
<div id="baz"></div> {{ notify_all("baz") }} {# or #} {{ notify_one("foo", "baz") }}
###添加选项
使用add()
方法添加通知时,有许多可用的选项
//Defaults listed below array( "message" => "", // The message to render, will be wrapped in p tags "title" => "", // The title to render, will be wrapped in h2 tags "class" => "notice", // css class to add to the notification div "type" => "flash", // flash or instant, instant lasts until a page refresh, flash lasts for one redirect "lifetime" => "5000", // Lifetime of the notification in ms "click_to_close" => false, //true or false, true will make notification disappear only on click, false will use lifetime "sticky" => false // Makes the notification sticky and not disappear )