开发者

accessing images

开发者 https://www.devze.com 2022-12-16 06:46 出处:网络
I am new to Symfony. I created a layout page in which I have this : <imgsrc=\"images/header.jp开发者_如何学编程g\" width=\"790\" height=\"228\" alt=\"\" />

I am new to Symfony.

I created a layout page in which I have this :

<img  src="images/header.jp开发者_如何学编程g" 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 ?


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


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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消