定制 pentiminax/ux-sweet-alert 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

pentiminax/ux-sweet-alert

最新稳定版本:v0.9.0

Composer 安装命令:

composer require pentiminax/ux-sweet-alert

包简介

SweetAlert2 integration for Symfony

README 文档

README

UX SweetAlert is a Symfony bundle that integrates the SweetAlert2 library into your Symfony applications. It provides PHP helpers and a Stimulus controller to easily display alerts and toast notifications.

Requirements

  • PHP 8.2 or higher
  • Symfony StimulusBundle
  • Composer

Installation

Install the library via Composer:

composer require pentiminax/ux-sweet-alert

Basic usage

To automatically display toasts and alerts in your templates, add the following Twig function in your base.html.twig (or the layout file):

{{ ux_sweet_alert_scripts() }}

Alerts

Inject the AlertManagerInterface and use the helper methods to create alerts:

use Pentiminax\UX\SweetAlert\AlertManagerInterface;

#[Route('/', name: 'app_homepage')]
public function index(AlertManagerInterface $alertManager): Response
{
    $alertManager->success(
        title: 'Update Successful',
        text: 'Your settings have been saved.'
    );

    return $this->redirectToRoute('dashboard');
}

Toasts

Inject the ToastManagerInterface service and create toasts:

use Pentiminax\UX\SweetAlert\Enum\Position;
use Pentiminax\UX\SweetAlert\ToastManagerInterface;

class HomeController extends AbstractController
{
    #[Route('/', name: 'app_homepage')]
    public function index(ToastManagerInterface $toastManager): Response
    {
       $toastManager->success(
            title: 'title',
            text: 'text',
            position: Position::TOP_END,
            showConfirmButton: false,
            timer: 3000,
            timerProgressBar: true
        );

        return $this->render('home/index.html.twig');
    }
}

Advanced documentation

统计信息

  • 总下载量: 2.86k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 22
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 22
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-03