dongliu6848
dongliu6848
2011-09-08 16:56

为什么我的dev前端控制器包含在Assetic URL中?

已采纳

I'm using Assetic to include Javascript files, but when used in the dev environment, /app_dev.php is added to the beginning of the URL, so the final url looks like /app_dev.php/js/something.js. This results in a 404 when trying to load the JS. When I access the site from the production environment the URLs don't include /app_dev.php and everything works fine.

I could add a conditional that checks if it's the dev environment and call str_replace on the URLs, but I'd like to solve the root of this problem, if possible.

Edit

@gilden, I would understand that in dev they would get processed every time, but the URLs simply result in 404s.

Here's my Assetic config:

assetic:
    debug:          %kernel.debug%
    use_controller: false
    filters:
        cssrewrite: ~
        # closure:
        #     jar: %kernel.root_dir%/java/compiler.jar
        # yui_css:
        #     jar: %kernel.root_dir%/java/yuicompressor-2.4.2.jar

And here's how I'm using it in my template (app/Resources/views/base.html.php)

foreach ($view['assetic']->javascripts(
            array('@AssetsBundle/Resources/public/js/*'), array(), array('output' => 'js/combined.js')) as $url) {
            echo 'url: ' . $url . '<br />';    
        }

I then include $url using a custom helper I wrote, but it already contains app_dev.php at that point.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • doufu2396 doufu2396 10年前

    I haven't used php templating in Symfony so I'm afraid I don't have the best answer. By using some custom code, you're probably circumventing some internal logic, which handles the request to a controller.

    As a workaround you could try removing assetic: use_controller: true from /app/config_dev.yml.

    点赞 评论 复制链接分享

相关推荐