gpt4 book ai didi

php - Symfony2 Assets 包问题

转载 作者:行者123 更新时间:2023-11-28 07:27:11 25 4
gpt4 key购买 nike

配置文件:

assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ FrontendBundle ]
#java: /usr/bin/java
ruby: /usr/bin/ruby
sass: /usr/bin/sass
read_from: %kernel.root_dir%/../../web/
write_to: %kernel.root_dir%/../../web/
filters:
cssrewrite: ~
scss:
style: 'expanded'
compass: true
apply_to: "\.scss$"
compass:
bin: /usr/bin/compass
images_dir: %kernel.root_dir%/../../src/FrontendBundle/Resources/assets/images
generated_images_path: %kernel.root_dir%/../../src/FrontendBundle/Resources/public/images/sprites
http_generated_images_path: /images/sprites

模板:

<?php foreach ($view['assetic']->stylesheets(
array('@FrontendBundle/Resources/assets/scss/homepage.scss'),
array('compass'),
array('output' => 'css/homepage.css')
) as $url):
$styles[] = '<link rel="stylesheet" href="'. $view->escape($url) .' " />' ?>
<?php endforeach; ?>

Prod 环境运行良好。生成css/homepage.css,结果html中有指向它的链接。

问题出在开发环境上。如果我尝试动态生成 css,我会收到“无法为命名路由生成 URL...”错误,在 config_dev.yml 中设置了“bundles”选项,在 roting_dev.yml 中设置了 assetic 路由。这只是我为这个问题找到的解决方案,没有一个有效。

如果我尝试做类似产品的操作,将“use_controller”设置为 false,在结果 html 中我会得到指向“homepage_homepage_1.css”的链接,而不是“homepage.css”,它不会生成。

最佳答案

你试过新的Asset component了吗?对于 Symfony 2.7

app/config/config.yml

framework:
assets:
version: 'v5'
version_format: '%%s?version=%%s'
base_path: ~
base_urls: ['http://cdn.example.com', 'https://secure.example.com']
packages:
scss:
base_path: bundles/mybundle/scss
compass:
base_path: bundles/mybundle/compass

然后你应该用类似的东西记忆起正确的样式表:

{{ asset('myscss.css', 'scss') }}
{# /bundles/mybundle/scss/myscss.css #}

{{ asset('mycompass.css', 'compass') }}
{# /bundles/mybundle/compass/mycompass.css #}

我建议您在 View 中使用 Twig,这样您就可以过滤变量 through an if statement (如 assetic)。

关于php - Symfony2 Assets 包问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31743636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com