定制 survos/bootstrap-bundle 二次开发

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

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

survos/bootstrap-bundle

最新稳定版本:2.0.216

Composer 安装命令:

composer require survos/bootstrap-bundle

包简介

Integrates a bootstrap theme with many extras in a Symfony application

关键字:

README 文档

README

⚠️ This bundle is no longer maintained.

Please use survos/tabler-bundle instead, which provides the same functionality with better support.

A common bootstrap layout, including menus and several components.

This bundle leverages several Symfony components, and as such loads several dependencies, and is a fairly opinionated bundles. Adhering to the coding suggestions offers several benefits.

Layout

All of the themes are based on Bootstrap 5.3, and tabler is the recommended one. The base layout has various menus: navbar, footer, page_header

Menus

The menu system is based on event listeners. While these are a bit complicated at first, benefits include:

  • Context-specific menus (e.g. a separate menu for each entity, e.g. a Project menu, with its own navbar and footer.
  • Automatic security -- does not render a menu item if IsGranted attribute blocks the user
  • Automatic translation: uses the controller name (rather than route name) as the default label.
bin/console survos:make:menu App
    #[AsEventListener(event: KnpMenuEvent::NAVBAR_MENU2, priority: 50)]
    public function navarButtonsMenu(KnpMenuEvent $event): void
    {
        $menu = $event->getMenu();
        $this->add($menu, 'app_homepage');
        $this->add($menu, 'event_index');
    }

    #[AsEventListener(event: KnpMenuEvent::NAVBAR_MENU)]
    public function navbarMenu(KnpMenuEvent $event): void
    {
        if (!$this->supports($event)) {
            return;
        }
    }

Pass context-specific menu data by first configuring the allowable fields in menu_options of survos_bootstrap.yaml

survos_bootstrap:
  routes:
      login: app_login
      logout: app_logout
      register: app_register
      homepage: app_homepage
  menu_options:
      entityClass: null
      project: null
      frontPage: false
      showAppMenu: false
{% block footer %}
<twig:menu :type="FOOTER_MENU" :caller="_self"
           :options="{owner: owner,
                entityClass: ownerClass,
               project:project|default(null)}"
               >
</twig:menu>

Entity Routes

Entity routes can be generated in the menu component without having to remember the parameters.

            if ($this->isGranted('ROLE_SUPER_ADMIN')) {
                $subMenu = $this->addSubmenu($menu, 'super_admin_index');
                $this->add($subMenu, 'owner_references', $owner);
                $this->add($subMenu, 'owner_dump', $owner, external: true);

the $owner class must implement getUniqueParameters(), which is used by the getRp() method. At the moment, this requires implementing the listener which is clumbsy :-(

)

symfony new my-app --webapp && cd my-app
composer req survos/bootstrap-bundle
composer req survos/maker-bundle --dev

bin/console importmap:require @tabler/core
echo "import '@tabler/core'; 
import '@tabler/core/dist/css/tabler.min.css';
" >> assets/app.js

@todo: 
{% extends "@SurvosBootstrap/%s/base.html.twig"|format(theme_option('theme')) %}


bin/console make:controller App
sed  -i "s|'/app'|'/'|" src/Controller/AppController.php # the landing page controller
cat > templates/app/index.html.twig <<'END'
{% extends 'base.html.twig' %}
{% block body %}
<twig:alert message="hello" dismissible="true">
        <twig:block name="alert_message">
            I can override the alert_message block and access the {{ message }} too!
        </twig:block>
    </twig:alert>
{% endblock %}
END

@todo:

  • make:create-user-command

A simple template with a navbar and login for Symfony, using Bootstrap 5

composer req survos/bootstrap-bundle
composer req survos/maker-bundle --dev

To set default values (@todo: install recipe)

# config/packages/bootstrap.yaml
bootstrap:
  widthFactor: 3
  height: 120
  foregroundColor: 'purple'
symfony new BootstrapDemo --webapp
bin/console make:controller AppController
composer req survos/bootstrap-bundle
echo "{{ 'test'|bootstrap }} or {{ bootstrap('test', 2, 80, 'red') }} " >> templates/app/index.html.twig
symfony server:start -d

Knp Menu Bundle

symfony new menu7 --webapp --version=next && cd menu7
composer config minimum-stability dev
composer config prefer-stable false
composer config extra.symfony.allow-contrib true
#sed -i 's/"6.4.*"/"^7.0"/' composer.json
composer update
#composer config repositories.knp_menu_bundle '{"type": "vcs", "url": "git@github.com:tacman/KnpMenuBundle.git"}'
composer require knplabs/knp-menu-bundle
composer req symfony/asset-mapper
bin/console make:controller -i Menu

cat > templates/menu.html.twig <<END
{% extends 'base.html.twig' %}
{% block body %}
    {{ knp_menu_render('App:Builder:mainMenu') }}
{% endblock %}  
END

cat > src/Menu/Builder.php << 'END'
namespace App\Menu;

use App\Entity\Blog;
use Knp\Menu\FactoryInterface;
use Knp\Menu\ItemInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;

final class Builder 
{

    public function mainMenu(FactoryInterface $factory, array $options): ItemInterface
    {
        $menu = $factory->createItem('root');

        $menu->addChild('Home', ['route' => 'app_app']);

        return $menu;
    }
}
END

symfony server:start -d
symfony open:local --path=/menu

twig bug

symfony new test --webapp --version=7.0 && cd test
composer require symfony/ux-twig-component symfony/asset-mapper 
composer req survos/bootstrap-bundle
composer req survos/api-grid-bundle
composer req survos/crawler-bundle
composer req survos/command-bundle
composer req survos/barcode-bundle
echo "import 'bootstrap/dist/css/bootstrap.min.css'" >> assets/app.js

bin/console make:controller App
sed  -i "s|'/app'|'/'|" src/Controller/AppController.php # the landing page controller
cat > templates/app/index.html.twig <<'END'
{% extends 'base.html.twig' %}
{% block body %}
<twig:alert message="hello" dismissible="true">
        <twig:block name="alert_message">
            I can override the alert_message block and access the {{ message }} too!
        </twig:block>
    </twig:alert>
{% endblock %}
END

symfony server:start -d
symfony open:local --path=/app

cd ../ux
./link ../bug
cd ../bug
symfony open:local --path=/app

survos/bootstrap-bundle 适用场景与选型建议

survos/bootstrap-bundle 是一款 基于 Twig 开发的 Composer 扩展包,目前已累计 6.59k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2022 年 07 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony-ux」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 survos/bootstrap-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 survos/bootstrap-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 survos/bootstrap-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 0
  • 开发语言: Twig

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-07-11