Ada*_*ski 10 php routing http-status-code-404 symfony assetic
我已经安装了Symphony2框架并创建了自己的bundle.我正在为我的js和css文件使用资产.
我在我的服务器上运行ubuntu并在我的本地机器上运行.
当我在本地访问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""
Run Code Online (Sandbox Code Playgroud)
我在网上搜索高低,我似乎无法弄清楚这一点.
我已经清除了缓存,资产转储,资产安装,所有权限都是正确的.
我的app routing.yml配置:
brs:
resource: "@BrsAdminBundle/Resources/config/routing.yml"
prefix: /
Run Code Online (Sandbox Code Playgroud)
我的bundle routing.yml配置
admin:
path: /admin/
defaults: { _controller: BrsAdminBundle:Admin:index }
Run Code Online (Sandbox Code Playgroud)
我的app配置:
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 }
Run Code Online (Sandbox Code Playgroud)
我的asset.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'
Run Code Online (Sandbox Code Playgroud)
我使用assetic的base.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>
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.
谢谢,
广告
您好,我认为您因 cssrewrite 而遇到问题。
你有两个选择;
指定输出目录
手动指向文件并在 twig 中使用 cssrewrite 过滤器。看这里; http://symfony.com/doc/current/cookbook/assetic/asset_management.html#fixing-css-paths-with-the-cssrewrite-filter
这是第一个选项的示例
您可以为资产指定输出目录。下面的示例指向 '/web/bundles/yourbundle/css' 执行assets:install --env=prodandassetic:dump --env=prod我认为您可以开始了。
{% stylesheets
'@admin_css'
output='bundles/yourbundle/css/admin_style.css'
%}
<link href="{{ asset_url }}?{{ AssetVersion }}" rel="stylesheet" type="text/css">
{% endstylesheets %}
Run Code Online (Sandbox Code Playgroud)
另外我必须提到,当您在 asset.yml 中定义资产时,会在公共资产目录中assetic:dump生成一个assets文件夹,在本例中您不需要该文件夹。要删除该文件夹,您可以在 twig 中使用此语法;
{% 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 %}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1529 次 |
| 最近记录: |