Membuat Anchor Image di CodeIgniter

3 Comments
Membuat Anchor Image di CodeIgniter
echo anchor($url, $text);

Karena codeigniter tidak menyediakan function untuk link image, berarti anda harus membuat function tambahan. Aktifkan file system/helper/url_helper.php

lalu dibagian paling bawah sisipkan code berikut:

if ( ! function_exists('anchor_img')){
function anchor_img($uri = '',$img = '', $title = '', $attributes = ''){
$title = (string) $title;

if ( ! is_array($uri)){
$site_url = ( ! preg_match('!^\w+://! i', $uri)) ? site_url($uri) : $uri;
}
else{
$site_url = site_url($uri);
}

if ($title == ''){
$title = $site_url;
}

if ($attributes != ''){
$attributes = _parse_attributes($attributes);
}

return '<a href="'.$site_url.'"><img src="'.base_url().'/'.$img.'" border=0></a>';
}
}

Untuk memanggilnya gunakan code ini:

echo anchor_img($url, $img);

$url : adalah link tujuan.
$img : adalah lokasi file image.

return ‘<a href=”‘.$site_url.’”><img src=”‘.base_url().’/’.$img.’” border=0></a>’;
Posted in: Web Development
About

kakaeriel a.k.a Ibnuh Hairil adalah seorang Web Programmer dan Web Design. Sangat menyukai sepak bola dan games, eksis dalam kegiatan-kegiatan sosial dan agama di wilayahnya, dan aktif di beberapa milis, komunitas dan jejaring sosial. ^^

3 Responses to Membuat Anchor Image di CodeIgniter

  1. Nice article!

  2. not working CI 2.0.3

    • Yes, this post for CI 1.7.2 :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>