如何在 Symfony2 中使用供应商捆绑资源
How to use vendor bundles resources in Symfony2
我知道这是一个非常基本的问题,我很困惑,因为我找不到一个好的答案。
假设我用 Composer 安装了 twbs/bootstrap 包,所以它位于正确的 vendor/twbs/bootstrap/ 目录中。现在,我需要做什么才能让它真正有用,即将包含 css/js 文件的 bootstrap/dist/ 文件夹复制到 web/ 文件夹?
是否有任何(半)智能 'Symfonic' 方法来处理这个问题,或者我应该 a) copy/update 手动需要的文件,b) 设置,例如一个繁重的复制任务?
如果重要的话,我在 Windows 7 上使用 Symfony 2.6。
一如既往,官方文档给出了答案:http://symfony.com/doc/current/cookbook/bundles/installation.html
您只能安装 symfony2 包的存储库。如果是 https://github.com/twbs/bootstrap,则不是。
你必须为 symfony2 找到另一个包做同样的事情,例如这个:https://github.com/braincrafted/bootstrap-bundle
正如所解释的那样 in their doc 就像几乎每个捆绑包文档一样,这里是安装此捆绑包的方法(其中大多数的过程是相同的):
Installation
BraincraftedBootstrapBundle should be installed using Composer:
{
"require": {
"braincrafted/bootstrap-bundle": "~2.0"
}
}
关于 Bootstrap 和 jQuery 的部分被剪掉了,与如何安装捆绑包没有直接关系,请去阅读文档。
Then add the bundle to your AppKernel.php:
# app/AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Braincrafted\Bundle\BootstrapBundle\BraincraftedBootstrapBundle(),
);
// ...
}
}
BraincraftedBootstrapBundle highly recommends you to use Assetic for
managing assets. If you do use Assetic for managing your assets, you
should now run the dump command.
php app/console assetic:dump
为了后代:
刚刚添加到我的资产配置中 config.yaml:
assetic:
assets:
bootstrap_css:
inputs:
- "%kernel.root_dir%/../vendor/twbs/bootstrap/dist/css/bootstrap.min.css"
filters:
- cssrewrite
output: bundles/twbs/bootstrap.css
刚刚添加到我的 base.html.twig 模板中 header 中的任意位置 :
<link rel="stylesheet" href="{{ asset('bundles/twbs/bootstrap.css') }}" media="screen" />
试试吧,不知道是不是'state of the art',但它确实有效。
感谢http://www.tutodidacte.com/symfony2-installer-bootstrap
我知道这是一个非常基本的问题,我很困惑,因为我找不到一个好的答案。
假设我用 Composer 安装了 twbs/bootstrap 包,所以它位于正确的 vendor/twbs/bootstrap/ 目录中。现在,我需要做什么才能让它真正有用,即将包含 css/js 文件的 bootstrap/dist/ 文件夹复制到 web/ 文件夹?
是否有任何(半)智能 'Symfonic' 方法来处理这个问题,或者我应该 a) copy/update 手动需要的文件,b) 设置,例如一个繁重的复制任务?
如果重要的话,我在 Windows 7 上使用 Symfony 2.6。
一如既往,官方文档给出了答案:http://symfony.com/doc/current/cookbook/bundles/installation.html
您只能安装 symfony2 包的存储库。如果是 https://github.com/twbs/bootstrap,则不是。
你必须为 symfony2 找到另一个包做同样的事情,例如这个:https://github.com/braincrafted/bootstrap-bundle
正如所解释的那样 in their doc 就像几乎每个捆绑包文档一样,这里是安装此捆绑包的方法(其中大多数的过程是相同的):
Installation
BraincraftedBootstrapBundle should be installed using Composer:
{ "require": { "braincrafted/bootstrap-bundle": "~2.0" } }
关于 Bootstrap 和 jQuery 的部分被剪掉了,与如何安装捆绑包没有直接关系,请去阅读文档。
Then add the bundle to your AppKernel.php:
# app/AppKernel.php class AppKernel extends Kernel { public function registerBundles() { $bundles = array( // ... new Braincrafted\Bundle\BootstrapBundle\BraincraftedBootstrapBundle(), ); // ... } }
BraincraftedBootstrapBundle highly recommends you to use Assetic for managing assets. If you do use Assetic for managing your assets, you should now run the dump command.
php app/console assetic:dump
为了后代: 刚刚添加到我的资产配置中 config.yaml:
assetic:
assets:
bootstrap_css:
inputs:
- "%kernel.root_dir%/../vendor/twbs/bootstrap/dist/css/bootstrap.min.css"
filters:
- cssrewrite
output: bundles/twbs/bootstrap.css
刚刚添加到我的 base.html.twig 模板中 header 中的任意位置 :
<link rel="stylesheet" href="{{ asset('bundles/twbs/bootstrap.css') }}" media="screen" />
试试吧,不知道是不是'state of the art',但它确实有效。 感谢http://www.tutodidacte.com/symfony2-installer-bootstrap