首先让我说我完全不知道我应该做什么,因为关于 Assetic 的文档和可用信息要么是有限的,要么是面向 Symfony 的。
这是我的文件夹结构。
Assetic
+ assets
+ css
+ example.css
+ docs
+ src
+ tests
+ vendor
+ index.php
+ styles.php
现在,我有以下测试代码。基本上我克隆了一份 Assetic 的干净副本并运行了composer install
. 然后我创建了一个文件,它只是用 HTMLs标签index.php
链接到我的文件。styles.php
<link>
这是我的styles.php
<?php
require 'vendor/autoload.php';
$assetPath = __DIR__.'/assets/css/example.css';
$assetBasePath = __DIR__.'/assets/css';
$asset = new Assetic\Asset\FileAsset($assetPath, array(), $assetBasePath, 'example.css');
header('Content-Type: text/css');
$asset->setTargetPath(__DIR__);
echo $asset->dump(new Assetic\Filter\CssRewriteFilter);
这是我的example.css
样式表。
body {
background-image: url('../img/background.png');
}
当我styles.php
在浏览器中加载时,我得到以下输出。
url('../img/background.png');
这与实际的 CSS 相同。如果我使用来自 Mr. Clay 的 CSS URI Rewriter,我会得到预期的输出。
url('/Assetic/assets/img/background.png');
那么我对 Assetic 做错了什么?我不知道我应该通过什么路径以及去哪里。
谢谢。