将HeadScript javascript与widmogrod/zf2 assetic模块和js组合在多个模块中


Combining HeadScript javascript with widmogrod/zf2-assetic-module and js in multiple modules

遇到一点障碍,我找不到任何支持文档。我的用例相当简单。Application模块的javascript应该进入头部,而我的另一个模块Foo也有应该进入头部的脚本。我认为这个Assetic模块可以解决这个问题。以下是我的推断:

应用程序配置

/**
 * Assetic
 */
'assetic_configuration' => array(
    'buildOnRequest'    => true,
    'cacheEnabled'      => false,
    'webPath'           => realpath('public/assets'),
    'basePath'          => 'assets',

     'default' => array(
        'assets' => array(
            '@base_css',
            '@head_js',
        ),
        'options' => array(
            'mixin' => true,
        ),
    ),
     'modules' => array(
        'application' => array(
            # module root path for yout css and js files
            'root_path' => __DIR__ . '/../assets',
            # collection of assets
            'collections' => array(
                'base_css' => array(
                    'assets' => array(
                        'css/*.css',
                    ),
                    'filters' => array(),
                    'options' => array(),
                ),
                'head_js' => array(
                    'assets' => array(
                        'js/*.js',
                    ),
                    'filters' => array(),
                ),
                'base_images' => array(
                    'assets'=> array(
                        'images/*.png',
                    ),
                    'options' => array(
                        'move_raw' => true,
                    )
                ),
            ),
        ),
    ),
),

然后在我的Foo模块中。。。

Foo模块配置

/**
 * Assetic
 */
'assetic_configuration' => array(
     'default' => array(
        'assets' => array(
            '@base_css',
            '@head_js',
        ),
        'options' => array(
            'mixin' => true,
        ),
    ),

    'modules' => array(
        'foo' => array(
            # module root path for yout css and js files
            'root_path' => __DIR__ . '/../assets',
            # collection of assets
            'collections' => array(
                'base_css' => array(
                    'assets' => array(
                        'css/*.css'
                    ),
                    'filters' => array(),
                    'options' => array(),
                ),
                'head_js' => array(
                    'assets' => array(
                        'js/*.js' // relative to 'root_path'
                    ),
                    'filters' => array(),
                    'options' => array(),
                ),
                'base_images' => array(
                    'assets'=> array(
                        'images/*.png'
                    ),
                    'options' => array(
                        'move_raw' => true,
                    )
                ),
            ),
        ),
    ),
),

不幸的是,有了这个配置,只有Foo模块的javascript才能进入head_js.js

如能提供任何帮助,不胜感激。

谢谢!

好的-我已经想好了。希望这有一天能帮助到其他人。我在上面提到的配置密钥并不是不准确的——但是——当考虑到一个秘密的未记录的功能时,它们并没有正确制作;必须打开源代码才能了解到在资产包中包含单词"head"实际上会将其自动加载到head中。这最终是一个不错的功能,但当你没有意识到它时,它真的会让人头疼。