tags:

views:

55

answers:

2

I am new to Symfony.

I created a layout page in which I have this :

<img  src="images/header.jpg" width="790" height="228" alt="" />

but the image isn't displayed in the page when accessed from the browser.

I put the file header.jpg in the web/images/ folder.

I thought I could learn Symfony in a week while working on a small project. is it possible ?

A: 

Use slash at the beginning like

<img  src="/images/header.jpg" width="790" height="228" alt="" />

You can also use image_tag (which is better for routing)

image_tag('/images/header.jpg', array('alt' => __("My image")))

In the array with parameters you can add all HTML attributes like width, height, alt etc.

P.S. IT's not easy to learn Symfony. You need much more time

Tom
I think Tom's got it here, are you trying to access the image from a dev controller? If so, and your paths are set to relative URLs like you pasted above, then your browser is looking for the image at /app_dev.php/images/header.jpg. Adding the forward slash to the beginning of the path makes it absolute and should fix your issue. Also, you can use the image_tag function without specifying /images/, it's added by default and the function will automatically adjust to dev controllers: image_tag('header.jpg', array('alt' => __('My image')))
Cryo
A: 

If you don't want a fully PHP generated image tag but just want the correct path to your image, you can do :

<img src="<?php echo image_path('header.jpg'); ?>"> width="700" height="228" alt="" />

Notice that the path passed to image_path excludes the /images part as this is automatically determined and created for you by Symfony, all you need to supply is the path to the file relative to the image directory.

You can also get to your image directory a little more crudely using

sfConfig::get('sf_web_dir')."/images/path/to/your/image.jpg"

It should be noted that using image_tag has a much larger performance cost attached to it than using image_path as noted on thirtyseven's blog

Hope that helps :)

argibson