1

我正在尝试将资产与 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');
4

1 回答 1

0

我最终将 Symfony 控制台连接到我的 Zend 项目,并稍微采用了资产的 DumpCommand 来完成这项工作(通过传递我的 DI 容器版本和分配的 AsseticManager)。

于 2012-05-17T20:28:50.760 回答