我已经安装了Symphony2框架并创建了自己的捆绑包。我的js和css文件使用assetic。
我在服务器上运行ubuntu,在本地机器上运行mint。
当我在本地访问app_dev.php时,所有资产都可以正常使用。
当我在本地访问app.php时,所有资产都可以正常使用。
然而,在我的服务器上,路由被渲染,但资产(css&js(我得到了404。
当我跟踪prod.log时,我得到一个未捕获的异常:
PHP Exception Symfony'Component'HttpKernel'Exception'NotFoundHttpException: "No route found for "GET /admin/css/875a243.css""
我在网上搜索了很多遍,似乎都搞不清楚。
我已经清除了缓存,资产转储,资产安装,所有权限都是正确的。
我的应用程序路由。yml配置:
brs:
resource: "@BrsAdminBundle/Resources/config/routing.yml"
prefix: /
我的捆绑包路由。yml配置
admin:
path: /admin/
defaults: { _controller: BrsAdminBundle:Admin:index }
我的应用配置:
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: assets.yml }
framework:
#esi: ~
#translator: { fallback: "%locale%" }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_proxies: ~
session: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
我的资产.yml配置:
assetic:
assets:
bootstrap_js:
inputs:
- '%Kernel.root_dir%/Resources/public/js/jquery-2.1.3.min.js'
- '%Kernel.root_dir%/Resources/public/js/bootstrap.min.js'
bootstrap_css:
inputs:
- '%Kernel.root_dir%/Resources/public/css/bootstrap.min.css'
- '%Kernel.root_dir%/Resources/public/css/bootstrap-theme.min.css'
admin_css:
inputs:
- '@BrsAdminBundle/Resources/public/css/styles.css'
使用assetic:的mybase.html.twig
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>{% block title %}BankRoll Supply{% endblock %}</title>
{% block stylesheets %}
{% stylesheets '@bootstrap_css' '@admin_css' %}
<link rel="stylesheet" type="text/css" href="{{ asset_url }}" />
{% endstylesheets %}
{% endblock %}
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
</head>
<body>
{% block body %}{% endblock %}
{% block javascripts %}
{% javascripts '@bootstrap_js' %}
<script type="text/javascript" src="{{ asset_url }}"></script>
{% endjavascripts %}
{% endblock %}
</body>
</html>
如有任何帮助,我们将不胜感激。
谢谢你,
Ad
嗨,我想你有问题是因为cssrewrite。
您有两种选择;
-
指定输出目录
-
手动指向您的文件,并在trick中使用cssrewrite过滤器。请参阅此处;http://symfony.com/doc/current/cookbook/assetic/asset_management.html#fixing-带有cssrewrite过滤器的css路径
这是第一个选项的示例
您可以为资产指定输出目录。下面的例子指向'/web/bundles/yourbundle/css'做一个assets:install --env=prod
和assetic:dump --env=prod
,我认为你可以继续了。
{% stylesheets
'@admin_css'
output='bundles/yourbundle/css/admin_style.css'
%}
<link href="{{ asset_url }}?{{ AssetVersion }}" rel="stylesheet" type="text/css">
{% endstylesheets %}
此外,我必须提到,当您在asset.yml中定义资产时,assetic:dump
会在您的公共资产目录中生成一个assets
文件夹,在这种情况下您不需要它。为了摆脱那个文件夹,你可以在trick中使用这个语法;
{% stylesheets
'@YourBundle/Resources/public/css/admin.css'
output='bundles/yourbundle/css/admin_style.css'
%}
<link href="{{ asset_url }}?{{ AssetVersion }}" rel="stylesheet" type="text/css">
{% endstylesheets %}