Skip to content

Instantly share code, notes, and snippets.

@adityamenon
Created May 27, 2012 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adityamenon/2815973 to your computer and use it in GitHub Desktop.
Save adityamenon/2815973 to your computer and use it in GitHub Desktop.
New url_helper anchor tag that allows for an image link - by InsiteFX
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Created with Php Designer 8.
* Created by: The Development Team.
* User: Raymond King aka: (InsiteFX)
* Date: 1/19/2012
* Time: 6:43:31 PM
* @copyright 1/15/2012 by Raymond L King.
*
* Class name: ./application/helpers/MY_url_helper.php
*
* To change this template use File | Settings | File Templates.
*/
// ------------------------------------------------------------------------
/**
* Anchor Image Link
*
* Creates an image anchor based on the local URL.
*
* Usage:
*
* Controller:
* $data['img'] = base_url().'assets/images/gravatar.jpg';
*
* View:
* <?php $img = base_url('assets/images/gravatar.jpg'); ?>
*
* <?php echo anchor_img('index.php/welcome', 'Image Test', $attr, $img); ?>
*
* @access public
* @param string the URL
* @param string the link title
* @param mixed any attributes
* @param string the image source path
* @return string
*/
if ( ! function_exists('anchor_img'))
{
function anchor_img($uri = '', $title = '', $attributes = '', $img_src = '', $img_only = FALSE)
{
$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);
}
$out = '';
if ($img_src == '')
{
$out = '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
}
else
{
$out = '<a href="'.$site_url.'"'.$attributes.'>'.'<img src="'.$img_src.'"></a>';
if ($img_only == FALSE)
{
$out .= '<a href="'.$site_url.'"'.$attributes.'>'.$title.'</a>';
}
}
return $out;
}
}
/* ------------------------------------------------------------------------
* End of file MY_url_helper.php
* Location: ./application/helpers/MY_url_helper.php
* ------------------------------------------------------------------------
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment