2

Assetic に関するドキュメントと入手可能な情報は限られているか、Symfony 指向であるため、何をすべきかまったくわかりません。

これが私のフォルダ構造です。

Assetic
   + assets
      + css
         + example.css
   + docs
   + src
   + tests
   + vendor
   + index.php
   + styles.php

今、私は次のテストコードを持っています。基本的に、Assetic のクリーン コピーを複製して実行しましcomposer installた。次に、HTMLタグを使用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 で何が間違っているのでしょうか? どのパスを通ってどこへ行くべきかわかりません。

ありがとう。

4

1 に答える 1

2

かなり苦労しましたが、最終的に(ウェブアセットのドキュメント、アセットのベースとなるpythonライブラリを読んだ後)ドキュメントの欠如に勝ちました。

どうぞ

<?php

require 'vendor/autoload.php';

$assetPath = __DIR__.'/assets/css/example.css';

$asset = new Assetic\Asset\FileAsset($assetPath, array(new Assetic\Filter\CssRewriteFilter), dirname($assetPath), '/assets/css');
// I assume the 'assets' directory is at the root of your website

header('Content-Type: text/css');

$asset->setTargetPath('/path/to/dumped/asset');
// As above, it's the path to the generated asset from your http root

echo $asset->dump();

よくわからないので、わからないことがあれば聞いてください。

于 2012-11-28T16:45:30.250 に答える