xm / flash-bundle
使在 Symfony 中添加和翻译闪存消息变得简单。
1.1.1
2017-07-18 21:06 UTC
Requires
- php: ^5.6 || ^7.0
- symfony/framework-bundle: ~3.0
- symfony/translation: ~3.0
Requires (Dev)
- mockery/mockery: ^0.9
- phpunit/phpunit: 5.7.*
- symfony/phpunit-bridge: ^3.0
- symfony/var-dumper: ^3.0
This package is auto-updated.
Last update: 2024-09-15 15:20:10 UTC
README
使在 Symfony 中添加和翻译闪存消息变得简单。
安装
步骤 1: 下载包
打开命令控制台,进入您的项目目录并执行以下命令以下载此包的最新稳定版本
$ php composer.phar require xm/flash-bundle
此命令需要 Composer。
步骤 2: 启用包
然后,通过将其添加到项目中的 app/AppKernel.php
文件中已注册的包列表中来启用该包
<?php // app/AppKernel.php // ... class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new XM\FlashBundle\XMFlashBundle(), ); // ... } }
步骤 3: 添加服务别名
添加以下内容将缩短对服务的调用
flash_handler: '@xm_flash.handler'
用法
处理程序将始终从默认翻译文件中提取消息,通常是 messages。
只有消息,没有翻译
$this->get('flash_handler')->add('success', 'The record was saved.');
带有翻译消息密钥和参数
$this->get('flash_handler')->add('success', 'app.message.entity_updated', ['%name%' => 'User']);