<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dragffy.com &#187; source code</title>
	<atom:link href="http://dragffy.com/blog/posts/tag/source-code/feed" rel="self" type="application/rss+xml" />
	<link>http://dragffy.com/blog</link>
	<description>The development, documentation, and blogging domain of Gabriel Dragffy.</description>
	<lastBuildDate>Wed, 16 Nov 2011 11:17:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>Linking images in Code Igniter</title>
		<link>http://dragffy.com/blog/posts/linking-images-in-code-igniter</link>
		<comments>http://dragffy.com/blog/posts/linking-images-in-code-igniter#comments</comments>
		<pubDate>Sun, 17 Feb 2008 15:42:11 +0000</pubDate>
		<dc:creator>Gabe</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://dragffy.com/blog/posts/linking-images-in-code-igniter</guid>
		<description><![CDATA[I&#8217;m a big fan of the PHP framework, CodeIgniter. However, until recently it has lacked an elegant way of nesting an image in an anchor tag. I had to resort to manually typing out HTML like this: &#60;a href="&#60;?=site_url?&#62;/controller/action"&#62;&#60;img src="&#60;?=base_url()?&#62;/images/button.gif"&#62;&#60;/a&#62; CodeIgniter 1.6 has been released, quickly followed by 1.6.1. This includes an image helper. One [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a big fan of the PHP framework, CodeIgniter. However, until recently it has lacked an elegant way of nesting an image in an anchor tag. I had to resort to manually typing out HTML like this:<br />
<code>&lt;a href="&lt;?=site_url?&gt;/controller/action"&gt;&lt;img src="&lt;?=base_url()?&gt;/images/button.gif"&gt;&lt;/a&gt;</code><br />
CodeIgniter 1.6 has been released, quickly followed by 1.6.1. This includes an image helper. One is still unable to elegantly link images using CI&#8217;s helpers. If you want to be able to do something like this:<br />
<code>&lt;?= anchor( 'controller/action', img( 'images/button.gif' )?&gt;</code></p>
<p>You could just comment out line 117 in <code>/system/helpers/url_helper.php</code> but that means you are altering CI core, which is not a good idea. For a start it will be overwritten when you upgrade and it is an inelegant hack.</p>
<p>A better bet is to create your own helper file and use it to override CodeIgniter&#8217;s one. This is dead-simple, just create a file called <code>MY_url_helper.php</code> in the following location <code>/system/application/helpers/</code>. Note that the <strong>MY_</strong> prefix is set in the config.php file under <code>$config['subclass_prefix'] = 'MY_';</code> so if you have changed that setting you will need to adjust your file-name accordingly.</p>
<p>Then just copy and paste the following in to it:<span id="more-17"></span></p>
<pre>&lt; ?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

if (! function_exists('anchor'))

{

 function anchor($uri = '', $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 = ' title="'.$title.'"';

 	}

 	else

 	{

 		$attributes = _parse_attributes($attributes);

 	}

return '<a href="'.$site_url.'">'.$title.'</a>';

 }

}

?&gt;</pre>
]]></content:encoded>
			<wfw:commentRss>http://dragffy.com/blog/posts/linking-images-in-code-igniter/feed</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

