CodeIgniter Forums

Full Version: Attaching images to my web-page
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]2mato[/eluser]
Hello there I am trying to attaching images to my first CodeIgniter web-page :-), I am using this :

1- In config.php I configer the base url as shown ===>
$config['base_url'] = "http://localhost/ci/";

2- when adding an image to a view file i do like this ===>
<img src='&lt;?php echo base_url(); ?&gt;images/login_icon.gif'/>

What I am asking do i have to echo the base_url every time i want to add image or is there a better way to do that, Thanks.

El Forum

[eluser]mdvaldosta[/eluser]
You don't have to use the base url, omitting it will just show the images from a relative path (which I prefer to do anyways).

El Forum

[eluser]2mato[/eluser]
[quote author="mdvaldosta" date="1300738597"]You don't have to use the base url, omitting it will just show the images from a relative path (which I prefer to do anyways).[/quote]

sorry but i did not understand how i can do that?
My images are in a folder called images and on the same level is the application folder for CodeIgniter.

El Forum

[eluser]Atharva[/eluser]
You can use img function in html helper
Code:
$this->load->helper('html');
echo img('images/picture.jpg');

So you don't have to use base_url() each time. More info here

El Forum

[eluser]2mato[/eluser]
[quote author="Atharva" date="1300802653"]You can use img function in html helper
Code:
$this->load->helper('html');
echo img('images/picture.jpg');

So you don't have to use base_url() each time. More info here[/quote]

Thanks that work very good .... :-)