CodeIgniter Forums
base_url() and url helper - Printable Version

+- CodeIgniter Forums (
+-- Forum: Archived Discussions (
+--- Forum: Archived Development & Programming (
+--- Thread: base_url() and url helper (/showthread.php?tid=28033)

Pages: 1 2

base_url() and url helper - El Forum - 02-28-2010

[quote author="elaniobro" date="1267339989"]
As for the img(); does that need to have a helper loaded,

Yup - it's part of the [url="/user_guide/helpers/html_helper.html"]HTML Helper[/url].

Quote:Also what is the benefit of using img(); vs base_url() within the <img> tag?

It means if you move files around, it's probably going to be less work.

Your code will look cleaner (faster to type, easier to debug). Consider the difference between these two lines:

<img src="&lt;?= base_url();?&gt;img/logo_tagline.png"/>

If you read the user guide (link above) for this function you'll see that there are also benefits if you decide to:
a) use a 'media server' to serve your images,
b) you want to add a lot of common meta data (title, width, height, etc) to more than one image - you can just pull that in from a common array. Similarly you don't have to change it in lots of places (as you would with <img >) if you want to make sweeping changes.

base_url() and url helper - El Forum - 02-28-2010

Thanks for the input. I do have a question though regarding the img(); How do you put the array's in for the attributes?

&lt;?= img('img/nav/nav_biography_a.png', array('id'=>'bio','height' => '100', 'width' => '20', 'alt' => 'bio'))?&gt;

viewing the source does not display any of the attributes.

after reading the wiki it says to do so as such:
$image_properties = array(
          'src' => 'images/picture.jpg',
          'alt' => 'Me, demonstrating how to eat 4 slices of pizza at one time',
          'class' => 'post_images',
          'width' => '200',
          'height' => '200',
          'title' => 'That was quite a night',
          'rel' => 'lightbox',


That method does not seem practical.

base_url() and url helper - El Forum - 02-28-2010

Got it, the array was in the wrong spot, and not including the 'src':
&lt;?= img(array('src'=>'img/nav/nav_biography_a.png','id'=>'bio','height' => '', 'width' => '', 'alt' => ''))?&gt;