ilyaserdyuk/notices

Zend Framework 2/3 通知

1.0 2017-07-21 19:04 UTC

This package is auto-updated.

Last update: 2024-09-29 05:14:35 UTC


README

显示消息的扩展,用于 Zend Framework 2/3 和 Twitter bootstrap 3 应用程序。

安装

使用 Composer

$ composer require ilyaserdyuk/notices:^1.0

并将其添加到布局中

<?= $this->notices() ?>

如何使用

从控制器发送消息

class IndexController extends AbstractActionController
{
    public function indexAction()
    {
        $this->notices()->addSuccessMessage('You successfully read this important alert message.');
        $this->notices()->addInfoMessage('This alert needs your attention, but it\'s not super important.');
        $this->notices()->addWarningMessage('Better check yourself, you\'re not looking too good.');
        $this->notices()->addErrorMessage('Change a few things up and try submitting again.');
    }
}

输出

<div class="alert alert-success alert-dismissible" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">&times;</span>
    </button>
    <strong>Well done!</strong>
    You successfully read this important alert message.
</div>

<div class="alert alert-info alert-dismissible" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">&times;</span>
    </button>
    <strong>Heads up!</strong>
    This alert needs your attention, but it's not super important.
</div>

<div class="alert alert-warning alert-dismissible" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">&times;</span>
    </button>
    <strong>Warning!</strong>
    Better check yourself, you're not looking too good.
</div>

<div class="alert alert-danger alert-dismissible" role="alert">
    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
        <span aria-hidden="true">&times;</span>
    </button>
    <strong>Oh snap!</strong>
    Change a few things up and try submitting again.
</div>

如何配置

您可以根据需要自定义输出模板,关闭转义并更改消息的标签。为此,请将以下内容添加到配置文件(config/autoload/global.php)中:

return [
    'view_helper_config' => [
        'notices' => [
            'auto_escape' => true,
            'template_string' => '<div class="alert alert-{class} alert-dismissible" role="alert">{text}</div>',
            'label_for_status' => [
                Message::CLASS_SUCCESS => 'Успешно:',
                Message::CLASS_INFO => 'Информация:',
                Message::CLASS_WARNING => 'Предупреждение:',
                Message::CLASS_ERROR => 'Ошибка:',
            ],
        ],
    ],
];