Symfony: image_tag() can you change the directory?
When u开发者_运维问答sing the image_tag()
method like this:
<?php echo image_tag('whatever.png') ?>
Symfony outputs an image like this:
<img src="/images/whatever.png"/>
By default it uses images
as the base images folder in your web directory. Can you change this default folder name in the Symfony config? Say I wanted to use img
instead of images
...
The config variable is named sf_web_images_dir_name
. You can see that in the source here. It can be set via sfConfig::set
or through app.yml
.
All told, it seems like the easiest way to do this is adding:
<?php sfConfig::set('sf_web_images_dir_name', 'img'); ?>
to the end of app.yml, simply because that is where config stuff is expected, but there are a variety of different ways to accomplish this.
I'm not sure if there is a way to configure this globally in a YAML settings file, but this should be easy to do in apps/frontend/config/frontendConfiguration.class.php
(or the equivalent for your application name), using sfConfig::set
:
<?php
class frontendConfiguration extends sfApplicationConfiguration
{
public function configure()
{
sfConfig::set('sf_web_images_dir_name', 'img');
}
}
精彩评论