ajt/flashbundle

Symfony 扩展包,用于管理闪存消息

1.5.0 2015-06-30 10:13 UTC

This package is not auto-updated.

Last update: 2024-09-14 15:16:38 UTC


README

Build Status SensioLabsInsight

AJT Flash Bundle 将通过简单的 API 管理 Symfony 闪存消息的使用。

使用方法

将 Flash 服务注入到任何服务中

<argument type="service" id="ajt.flash" />

在服务中使用它

class MyClass
{

    private $flash;

    public function __construct(FlashInterface $flash)
    {
        $this->flash = $flash;
    }

    public function goThings()
    {
        ...
        $this->flash->success("Well done");
    }
}

在模板中使用 twig 函数,

{{ ajt_flash() }}

或者如果您只想显示某些类型的信息

{{ ajt_flash('error') }}

标准类型

默认情况下,Flash 扩展包将支持标准的 Bootstrap 警告类型。

// Set a custom type

$flash->set('my message', 'myType');

// Bootstrap
$flash->success('my message');
$flash->error('my message');
$flash->info('my message');
$flash->warning('my message');

自定义 CSS

可以通过修改配置来设置自定义 CSS 类。

ajt_flash:
	default_class: alert # Added to every flash
	
	# CSS to add to the standard flash types - default to bootstrap
	core:
		success: alert-success
		error: alert-danger
		info: alert-info
		warning: alert-warning
	
	# Add a custom flash type called myType with the css myCss
	custom:
		myType:
			type: myType
			css: myCss