Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top