CodeIgniter Forums
Attaching images to my web-page - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Attaching images to my web-page (/showthread.php?tid=39791)



Attaching images to my web-page - El Forum - 03-21-2011

[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.


Attaching images to my web-page - El Forum - 03-21-2011

[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).


Attaching images to my web-page - El Forum - 03-21-2011

[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.


Attaching images to my web-page - El Forum - 03-22-2011

[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


Attaching images to my web-page - El Forum - 03-22-2011

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