seegno/bootstrap-bundle

Symfony2 的 Bootstrap 工具

安装数: 3,940

依赖项: 0

建议者: 0

安全: 0

星标: 3

关注者: 5

分支: 2

开放问题: 0

语言:HTML

类型:symfony-bundle

2.0.0 2016-06-21 12:52 UTC

This package is not auto-updated.

Last update: 2024-09-25 11:36:58 UTC


README

Bootstrap 工具用于 Symfony3

1. 安装

1.1. 将包添加到您的 composer.json

$ php composer.phar require seegno/bootstrap-bundle dev-master

1.2. 在 app/AppKernel.php 中注册该包

public function registerBundles()
{
    return array(
        // ...
        new Seegno\BootstrapBundle\SeegnoBootstrapBundle()
    );
}

1.3. (可选)从您的 web 文件夹中创建 twbs/bootstraptwbs/bootstrap/fonts 的符号链接。

$ ln -s ../vendor/twbs/bootstrap bootstrap
$ ln -s ../vendor/twbs/bootstrap/fonts fonts

2. 使用

模板

如果您想扩展 SeegnoBootstrapBundle 的模板之一,您需要将包添加到 Assetic 配置

# app/config.yml
assetic:
    bundles:
        - SeegnoBootstrapBundle

表单

要使用 SeegnoBootstrapBundle 的表单主题,只需将其 导入

{# some_view.html.twig #}
{% form_theme form 'SeegnoBootstrapBundle:Form:layout.html.twig' %}

或者,将其添加到 Twig 配置

# app/config.yml
twig:
    form:
        resources: ['SeegnoBootstrapBundle:Form:layout.html.twig']

警告

有两个 twig 函数 帮助您处理闪存消息

一次性显示所有

渲染所有 FlashBag。您可以在 视图 的任何位置包含以下 twig 函数

{# some_view.html.twig #}
{{ seegno_bootstrap_alerts() }}

默认情况下,将渲染 "success"、"info"、"warning" 和 "danger" 闪存。您可以在 SeegnoBootstrap 配置 中更改此设置

# app/config.yml
seegno_bootstrap:
    alerts: ["success", "info", "warning", "danger"]

或者,如果您想捕获任何 闪存,请关闭 strict 选项

{# some_view.html.twig #}
{{ seegno_bootstrap_alerts(false) }}
仅显示您想要的

单独渲染 闪存(这将查找 FlashBag 上的给定键)

{# some_view.html.twig #}
{{ seegno_bootstrap_alert('success') }}

您也可以使用此 twig 函数 添加消息(不将其添加到 FlashBag

{# some_view.html.twig #}
{{ seegno_bootstrap_alert('success', 'Your message here') }}

导航

导航利用了 KnpMenuBundle。使用包含的 导航布局

# app/config.yml
knp_menu:
    twig:
        template: SeegnoBootstrapBundle:Nav:layout.html.twig

或者,在 twig 函数 中使用它

{{ knp_menu_render('main', { 'template': 'SeegnoBootstrapBundle:Nav:layout.html.twig' }) }}

此外,为了使菜单更容易定义,我们包含了一个自定义的 MenuProvider,用于使用 yaml 定义菜单。您可以按以下方式定义菜单

# app/config.yml
seegno_bootstrap:
    navs:
        menus:
            main:
                childrenAttributes: { class: 'nav nav-pills' }
                items:
                    homepage: { label: 'Pages', route: 'homepage' }
                    about:    { label: 'About', route: 'about' }
                    blog:     { label: 'Blog', route: 'blog', extras: { 'routes': [{ pattern: '/^blog/' }] } }

MenuProvider 提供了一些菜单项附加功能

  • 子菜单:要渲染为菜单项子项的另一个菜单的键。
  • 角色:一个数组,设置为额外的参数,用于检查用户是否有权访问特定的菜单项。

包含的 twig 模板 也有一些附加功能

  • 包含:设置为额外参数的模板位置,例如 SeegnoBootstrapBundle:Example:menuitem.html.twig
  • 渲染:设置为额外参数的控制器,例如 SeegnoBootstrapBundle:Example:menuitem

分页

分页利用了 KnpPaginatorBundle,如果您需要分页,我们建议您使用它。

我们包含了两种不同的视图:一个 默认分页 和一个 分页器

将其添加到 KnpPaginator 配置

# app/config.yml
knp_paginator:
    template:
        pagination: SeegnoBootstrapBundle:Pagination:layout.html.twig

或者,只需使用 twig 函数

{{ knp_pagination_render(pagination, 'SeegnoBootstrapBundle:Pagination:pager.html.twig') }}

请参阅示例部分以获取更多信息。

3. 示例

该包包含一些示例。请检查 Controller/ExampleController.php 中的代码以及相关的 视图

如果您想在浏览器中查看它们,请将以下路由添加到您的路由文件中

# app/routing_dev.yml
seegno_bootstrap_example:
    resource: "@SeegnoBootstrapBundle/Resources/config/routing/example.yml"
    prefix: /seegno/bootstrap

以及,seegno_bootstrap 菜单

# app/config_dev.yml
seegno_bootstrap:
    seegno_bootstrap_example:
        childrenAttributes: { class: 'nav nav-pills nav-stacked'}
        items:
            alerts:     { label: 'Alerts', route: 'seegno_bootstrap_alerts' }
            forms:      { label: 'Forms', route: 'seegno_bootstrap_forms' }
            navs:       { label: 'Navs', route: 'seegno_bootstrap_navs' }
            pagination: { label: 'Pagination', route: 'seegno_bootstrap_pagination' }
            something:  { extras: { include: 'SeegnoBootstrapBundle:Example:menuitem.html.twig' } }

4. 风格指南

拥有一个风格指南总是很有帮助。为了做到这一点,将以下条目添加到您的 routing_dev.yml 文件中

# app/routing_dev.yml
seegno_bootstrap_styleguide:
    resource: "@SeegnoBootstrapBundle/Resources/config/routing/styleguide.yml"
    prefix: /seegno/bootstrap

接下来,您需要覆盖 Twig 模板,这样您就可以通过访问开发模式下的 /seegno/bootstrap/styleguide 来查看风格指南。创建文件 app/Resources/SeegnoBootstrapBundle/views/StyleGuide/index.html.twig,内容如下

{% extends 'SeegnoBootstrapBundle:StyleGuide:base.html.twig' %}

{% block stylesheets %}
    {% stylesheets filter="cssrewrite,?yui_css"
        'bundles/acmeproject/less/main.less'
    %}
        <link href="{{ asset_url }}" type="text/css" rel="stylesheet" />
    {% endstylesheets %}
{% endblock stylesheets %}

现在,您可以通过访问开发模式下的 /seegno/bootstrap/styleguide 来查看 Bootstrap 组件在您的应用程序中的外观。

5. 高级

待办。