5

I have create a folder named img which contains some images. However, when I try to access it in the url, such as:

http://mydomain.dev/app_dev.php/img/1.png

it doesn't work

Symfony returns me an error saying: No route found for "GET /img/1.png"

However, if I do the following:

http://mydomain.dev/img/1.png

it works !

I am using Apache and running it on Mac OSX Mavericks.

How can I access it in app_dev.php even if it is not a route but a file ?

2
  • I don't know much about symfony but usually rule is : "if file not exists route it via app_dev.php" so you may need to check your .htaccess file and rewrite rules. I don't think you should need a route for existing file (especially for an asset) Commented Jun 18, 2014 at 21:19
  • 1
    Learn about production and development modes in Symfony2 :). Commented Jun 18, 2014 at 21:22

2 Answers 2

5

if you insert your image in web/img/1.png and you want to point to it in twig file try:

<img src="{{ asset('img/1.png') }}" />
Sign up to request clarification or add additional context in comments.

4 Comments

That sounds interesting ! If I needed the path in the css file, what do you suggest ?
The same way :) <link href="{{ asset('css/blog.css') }}" rel="stylesheet" type="text/css" />
@jakon I'm sorry, I meant in the css file, like in background-color: url('img/1.png')
@CoachNono To set those paths in CSS files, you should use Assetic. It can rewrite paths in CSS files, see symfony.com/doc/current/cookbook/assetic/…
1

app_dev.php maps your request to router, which forward request to specific controller. Don't expect valid route to static files. Static files can be added with full path to file(ofc. your static files should be in your web direcory), or by Twig, which can render current path to file.

2 Comments

How does the less filter works ? It maps the files in the css folder. Or the files in /bundles/name/files , are they not mapped in the app_dev.php ?
Files from your bundle public directory are 'mapped' from your view. It has nothing common with router. Read about path to statis files here: symfony.com/doc/current/book/templating.html#linking-to-assets

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.