1

代码有什么问题

我想在加载时将 a.js 和 b.js 合二为一

配置.yml

# Assetic Configuration
assetic:
    debug:          %kernel.debug%
    use_controller: false
    bundles:        ['AcmeDemoBundle']
    #java: /usr/bin/java
    filters:
        cssrewrite: ~
        #closure:
        #    jar: %kernel.root_dir%/Resources/java/compiler.jar
        #yui_css:
        #    jar: %kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar
        uglifyjs2: %kernel.root_dir%

查看文件

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="" content="">
<link href="<?php echo $view['assets']->getUrl('bundles/acmedemo/css/a.css') ?>" rel="stylesheet" type="text/css" />
<!--<script src="<?php echo $view['assets']->getUrl('bundles/acmedemo/js/a.js') ?>" type="text/javascript" /></script>-->
<?php foreach ($view['assetic']->javascripts(
    array('@AcmeDemoBundle/Resources/public/js/a.js',
            '@AcmeDemoBundle/Resources/public/js/b.js'
    ),
    array('uglifyjs2')
) as $url): ?>
    <script type="text/javascript" src="<?php echo $view->escape($url) ?>"></script>
<?php endforeach; ?>
</head>
<body>

<div class="c2">Hello</div>

</body>
</html>

控制器

/**
 * @Route("/test", name="_demo_contact")
 * @Template()
 */
public function testAction(){
   return $this->render('AcmeDemoBundle:Demo:a.html.php');
}
4

1 回答 1

0

看看这一段http://symfony.com/doc/current/cookbook/assetic/asset_management.html#controlling-the-url-used

当您打开 php 版本时,您会看到您应该作为第三个参数传递带有一些output值的数组。

例如

<?php foreach ($view['assetic']->javascripts(
        array('@AcmeDemoBundle/Resources/public/js/a.js',
              '@AcmeDemoBundle/Resources/public/js/b.js'
        ),
        array('uglifyjs2'),
        array('output' => 'js/compiled/main.js')
      ) as $url): ?>
    <script type="text/javascript" src="<?php echo $view->escape($url) ?>"></script>
<?php endforeach; ?>
于 2013-07-22T19:14:12.407 回答