我正在尝试将资产与 Twig(在 Zend 上)连接起来。debug=false 似乎可以正常工作,但我无法理解它对开发的作用。
基本上,当调用这个时:
{% javascripts 'static/js/*.js' %}
<p>{{asset_url}}</p>
{% endjavascripts %}
它输出生成的 javascript 文件名列表(这很好):
js/d19cc07_part_1_jquery-1.7.2.min_6.js
js/d19cc07_part_1_jquery.cookie_7.js
js/d19cc07_part_1_jquery.jeditable.mini_8.js
但这些文件不是由 Writer 生成的(它只生成 js/d19cc07.js)。对于 debug=false 它只输出一个文件名并正确呈现它。
那么我在这里错过了什么?
这是我初始化它的方式:
//Assetic
$factory = new \Assetic\Factory\AssetFactory(APP_BASE_PATH . '/public/');
$factory->setDebug(true);
$am = new \Assetic\Factory\LazyAssetManager($factory);
//enable loading assets from twig templates
$loader = new \Twig_Loader_Filesystem(array());
$loader->addPath(APP_BASE_PATH.'/application/templates/default');
//Init twig
$twig = new \Twig_Environment($loader);
$twig->addExtension(new \Assetic\Extension\Twig\AsseticExtension($factory));
$am->setLoader('twig', new \Assetic\Extension\Twig\TwigFormulaLoader($twig));
$templates = array('/index/index.html'); //An array containing full paths to my templates
foreach ($templates as $template) {
$resource = new \Assetic\Extension\Twig\TwigResource($loader, $template);
$am->addResource($resource, 'twig');
}
//Writer
$writer = new \Assetic\AssetWriter(APP_BASE_PATH . '/public/static/assetic');
$writer->writeManagerAssets($am);
echo $twig->render('index/index.html');