tourze/weui-bundle

A Symfony Bundle for WeUI frontend framework integration

Installs: 2 913

Dependents: 4

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

Type:symfony-bundle

pkg:composer/tourze/weui-bundle

This package is auto-updated.

Last update: 2025-11-03 03:47:07 UTC


README

PHP Version Require License Build Status Coverage Status

English | 中文

A Symfony Bundle that provides simple integration with WeUI frontend framework. Main features include:

  • Quick rendering of success and error pages with WeUI styling
  • Support for custom titles and subtitles
  • Control over action button display (showOp parameter)
  • Company name configuration via environment variables
  • Automatic copyright year generation
  • Mobile-optimized responsive design

Installation

Install via Composer:

composer require tourze/weui-bundle

Quick Start

After installation, the bundle will be automatically registered. You can immediately start using the NoticeService in your controllers:

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use WeuiBundle\Service\NoticeService;

class DemoController extends AbstractController
{
    #[Route('/success', name: 'app_success')]
    public function success(NoticeService $noticeService): Response
    {
        return $noticeService->weuiSuccess('Operation Successful', 'Data has been processed');
    }

    #[Route('/error', name: 'app_error')]
    public function error(NoticeService $noticeService): Response
    {
        return $noticeService->weuiError('Operation Failed', 'Please try again later');
    }
}

Basic Usage

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use WeuiBundle\Service\NoticeService;

class DemoController extends AbstractController
{
    #[Route('/success', name: 'app_success')]
    public function success(NoticeService $noticeService): Response
    {
        return $noticeService->weuiSuccess('Operation Successful', 'Data has been processed');
    }

    #[Route('/error', name: 'app_error')]
    public function error(NoticeService $noticeService): Response
    {
        return $noticeService->weuiError('Operation Failed', 'Please try again later');
    }
}

API Reference

NoticeService

weuiSuccess(string $title, string $subTitle = '', bool $showOp = true): Response

Renders a success page with green checkmark icon.

Parameters:

  • $title (string): Main title text
  • $subTitle (string, optional): Subtitle text below the main title
  • $showOp (bool, optional): Whether to show the "Close Page" button (default: true)

Returns: Response object containing the rendered HTML

weuiError(string $title, string $subTitle = '', bool $showOp = true): Response

Renders an error page with warning icon.

Parameters:

  • $title (string): Main title text
  • $subTitle (string, optional): Subtitle text below the main title
  • $showOp (bool, optional): Whether to show the "Close Page" button (default: true)

Returns: Response object containing the rendered HTML

Environment Configuration

Set the company name in your .env file, which will be displayed at the bottom of the page:

COMPANY_NAME=Your Company Name

Advanced Usage

Hiding Operation Buttons

If you want to hide the "Close Page" button:

// Success page without close button
return $noticeService->weuiSuccess('Success', 'Task completed', false);

// Error page without close button
return $noticeService->weuiError('Error', 'Something went wrong', false);

Custom Templates

The bundle uses the following templates:

  • @Weui/success.html.twig - Success page template
  • @Weui/failed.html.twig - Error page template
  • @Weui/base.html.twig - Base template

You can override these templates in your application by creating them in your templates/bundles/WeuiBundle/ directory.

Testing

Run unit tests:

./vendor/bin/phpunit packages/weui-bundle/tests

License

This project is licensed under the MIT License - see the LICENSE file for details.