场景:
js,css不能直接放在view底下,symfony框架路由不识别那样的路径
解决方法:
- 安装assetic-bundle,并在Appkernel.php 中enable,并在config.yml 中 minimal configureation
$ composer require symfony/assetic-bundle
//app/AppKernel.php
public function registerBundles() {
$bundles = array( *// ...*
new Symfony\Bundle\AsseticBundle\AsseticBundle(),
);
*// ...*
}
//app/config/config.yml 添加配置
assetic:
debug: '%kernel.debug%'
use_controller: '%kernel.debug%'
filters:
cssrewrite: ~
- 用法: 然后在web 文件夹下面建css,js 并把css,js 文件放入,然后在view中按如下调用就ok了
{% block includes %}
<link href="{{ asset('css/libs/bootstrap.min.css') }}" type="text/css" rel="stylesheet"/>
<link href="{{ asset('css/libs/bootstrap.min.css') }}" type="text/css" rel="stylesheet"/>
<link href="{{ asset('css/main.css') }}" type="text/css" rel="stylesheet"/>
{% endblock %}
网友评论