<?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; CodeIgniter</title>
	<atom:link href="http://dragffy.com/blog/posts/category/programming/frameworks/codeigniter-frameworks-programming/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>CodeIgniter 1.7: The URI you submitted has disallowed characters.</title>
		<link>http://dragffy.com/blog/posts/codeigniter-17-the-uri-you-submitted-has-disallowed-characters</link>
		<comments>http://dragffy.com/blog/posts/codeigniter-17-the-uri-you-submitted-has-disallowed-characters#comments</comments>
		<pubDate>Tue, 14 Jul 2009 10:24:17 +0000</pubDate>
		<dc:creator>Gabe</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Information]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dragffy.com/blog/?p=134</guid>
		<description><![CDATA[I was getting the above error from CodeIgniter after urlencoding some base64 encoded binary data and passing it as a URI parameter to CodeIgniter. I looked in the config.php file and found that percent signs were allowed here: $config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-'; After some hunting around I found that CodeIgniter is not accepting this in [...]]]></description>
			<content:encoded><![CDATA[<p>I was getting the above error from CodeIgniter after urlencoding some base64 encoded binary data and passing it as a URI parameter to CodeIgniter. I looked in the config.php file and found that percent signs were allowed here:<br />
<code>$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';</code></p>
<p>After some hunting around I found that CodeIgniter is not accepting this in the URI because the actual characters (that are encoded) fall outside the ASCII range. CodeIgniter is actually decoding the characters before testing them. The fix was quite simple, open up <code>libraries/URI.php</code> and go to line 189 where it says:<br />
<code>if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str))</code><br />
and change it to:<br />
<code><br />
if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", rawurlencode($str)))</code></p>
<p>Basically wrapping <code>$str</code> in the <code>urlencode()</code> function.</p>
]]></content:encoded>
			<wfw:commentRss>http://dragffy.com/blog/posts/codeigniter-17-the-uri-you-submitted-has-disallowed-characters/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>An alternative img() helper function for CodeIgniter</title>
		<link>http://dragffy.com/blog/posts/an-alternative-img-helper-function-for-codeigniter</link>
		<comments>http://dragffy.com/blog/posts/an-alternative-img-helper-function-for-codeigniter#comments</comments>
		<pubDate>Wed, 20 May 2009 09:59:47 +0000</pubDate>
		<dc:creator>Gabe</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Information]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Operating System]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Server]]></category>

		<guid isPermaLink="false">http://dragffy.com/blog/?p=103</guid>
		<description><![CDATA[It is my opinion that CodeIgniter&#8217;s default img() function that comes in the HTML Helper could have been easier to use. As it is if you want to give your image a name css class you have to define an array consisting of these attributes. That takes up space and makes the code less readable [...]]]></description>
			<content:encoded><![CDATA[<p>It is my opinion that CodeIgniter&#8217;s default img() function that comes in the HTML Helper could have been easier to use. As it is if you want to give your image a name css class you have to define an array consisting of these attributes. </p>
<p>That takes up space and makes the code less readable for non-PHP programmers. Since I work closely with a web designer who is good with HTML but gets lost in PHP I want to leverage the pragmatic power of PHP to automate repetitive tasks (like typing out an entire HTML image tag), but at the same time the result needs to be obvious to a non-programmer but also shorter than the HTML equivalent. I feel the img() helper in CodeIgniter falls short of both these requirements.</p>
<p>CodeIgniter&#8217;s img() helper also takes a second parameter, a boolean, this decides whether the index.php file is included in the image path, good if you are using a media controller. For 99.9% of my sites I don&#8217;t need these. Therefore I wrote my own helper.</p>
<p>The file is called <code>MY_html_helper.php</code> and lives inside the folder <code>system/application/helpers</code>. As with other extensions to the CI core the prefix <code>MY_</code> is determined in your config file, so change <code>MY_</code> to whatever it should be. Add the following code to the file:</p>
<pre>
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');

function img($imgName, $attrs=FALSE)
{
	$CI =&amp; get_instance();

	if (strpos($imgName, 'http') === 0) return;

	$imgPath = $CI-&gt;config-&gt;item('base_url');

	if ( ! $imgDir = $CI-&gt;config-&gt;item('image_dir')) $imgDir = 'assets/images/';

	$img = $imgPath.$imgDir.$imgName;

	$str = '&lt;img src=&quot;'.$img.'&quot; ';

	if ($attrs) $str .= $attrs.&quot; &quot;;

	$str .= &quot;/&gt;&quot;;

	return $str;
}
</pre>
<p>All you have to make sure you do is load the html helper: <code>$this->load->helper('html');</code> in your controller,<br />
or put it in the array of helpers in <code>system/application/config/autoload.php</code>.</p>
<p>The helper assumes images live in the folder <code>assets/images</code> which lives alongside the <code>system</code> folder. If this is not where you put your images then you can specify an alternative directory in your config.php file. Simply add a line that looks like this to config.php: <code>$config['image_dir'] = 'alternative/path/images/';</code>. Don&#8217;t forget the trailing slash at the end. This <code>alternative</code> folder would live at the very top level of your application, alongside <code>index.php</code>.</p>
<p>Using the helper is easy and straightforward: <code>&lt;?=img('example.gif')?&gt;</code></p>
<p>Will produce <code>&lt;img src=&quot;http://mysite.com/assets/images/example.gif&quot; /&gt;</code>.</p>
<p>Any additional attributes you want in the html tag can be written as per usual as the second parameter. For example if you want to give the image an alt attribute and class:<br />
<code>&lt;?=img('example.gif', 'class=&quot;myclass&quot; alt=&quot;Example Image&quot;')?&gt;</code></p>
<p>Will produce:</p>
<pre>&lt;img src=&quot;http://mysite.com/assets/images/example.gif&quot; class=&quot;myclass&quot; alt=&quot;Example Image&quot; /&gt;</pre>
<p>The only hard part about this is making sure you get the single and double quotes correct in the second parameter.</p>
<p>Cheers</p>
]]></content:encoded>
			<wfw:commentRss>http://dragffy.com/blog/posts/an-alternative-img-helper-function-for-codeigniter/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Making CodeIgniter&#8217;s Profiler AJAX compatible</title>
		<link>http://dragffy.com/blog/posts/making-codeigniters-profiler-ajax-compatible</link>
		<comments>http://dragffy.com/blog/posts/making-codeigniters-profiler-ajax-compatible#comments</comments>
		<pubDate>Tue, 13 Jan 2009 09:21:08 +0000</pubDate>
		<dc:creator>Gabe</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Operating System]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dragffy.com/blog/?p=80</guid>
		<description><![CDATA[Modern web applications almost all make use of AJAX to enhance their user appeal. However, AJAX can be hard to debug, especially when all the traditional tools do little to help. When doing standard PHP coding CodeIgniter (CI) offers a profiler which will be appended to the bottom of generated pages. This gives you information [...]]]></description>
			<content:encoded><![CDATA[<p>Modern web applications almost all make use of AJAX to enhance their user appeal. However, AJAX can be hard to debug, especially when all the traditional tools do little to help. When doing standard PHP coding CodeIgniter (CI) offers a profiler which will be appended to the bottom of generated pages. This gives you information on the request that was recently processed, including any POST or GET values passed to the script, how long execution took and how long any SQL queries took as well as what those queries actually were. During development I find this information indispensable to make sure my SQL queries are correct and things are working as I want.</p>
<p>However, when coding up AJAX aspects of the application this doesn&#8217;t work very well, any page fragments fed back to the JavaScript will have the profiler stuck at the bottom, and since these fragments are usually inserted inside DIVs the profiler cannot be read in it&#8217;s entirety, or it breaks the layout, or more likely, both of the above. Therefore I set out to find a way of making it AJAX compatible, so that it would always end up at the bottom of the page, even when it was originally returned appended to a page fragment. In the end this turned out easier than anticipated.</p>
<p>One small change needs to be  made to your footer, you need to create an empty div with an ID of &#8220;debug&#8221;, this div will hold the profiler, so place the div where you want the profiler. The advantage with this is that you cannot see it when it is empty so it could even be left in for production code. The div looks like this:<br />
<code>&lt;div id="debug"&gt;&lt;/div&gt;</code></p>
<p>Now we need to extend, or rather override the CI profiler so create the file <code>system/application/libraries/MY_Profiler.php</code></p>
<p>Replace MY_ with the value of <code>$config['subclass_prefix']</code> found in your config file, by default it is MY_.</p>
<p>Next paste the following code in to it. Remember to change the name of the class as dictated by the filename you use, also change the name of the constructor function too. You can also change the script line to load the jQuery library from one of your servers, or even rewrite the entire script section to use any JavaScript you like.</p>
<pre>
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class MY_Profiler extends CI_Profiler
{
    function MY_profiler()
    {
        parent::CI_Profiler();
    }

    function run()
    {
            $output = &lt;&lt;&lt;ENDJS
&lt;script src=&quot;http://code.jquery.com/jquery-latest.js&quot; /&gt;
&lt;script type=&quot;text/javascript&quot; language=&quot;javascript&quot; charset=&quot;utf-8&quot;&gt;
// &lt; ![CDATA[
    $(document).ready(function() {
        var html = $('#codeigniter_profiler').clone();
        $('#codeigniter_profiler').remove();
        $('#debug').hide().empty().append(html).fadeIn('slow');
    });
// ]]&gt;
&lt;/script&gt;
ENDJS;
            $output .= &quot;&lt;div id='codeigniter_profiler' style='font-size: 0.7em; clear:both;background-color:#fff;padding:10px;'&gt;&quot;;
            $output .= $this-&gt;_compile_uri_string();
            $output .= $this-&gt;_compile_controller_info();
            $output .= $this-&gt;_compile_memory_usage();
            $output .= $this-&gt;_compile_benchmarks();
            $output .= $this-&gt;_compile_get();
            $output .= $this-&gt;_compile_post();
            $output .= $this-&gt;_compile_queries();
            $output .= '&lt;/div&gt;';
            return $output;
    }
}</pre>
<p>If you have already loaded a jQuery library in your header somewhere then make sure this ajax fragment doesn&#8217;t load jQuery again &#8211; otherwise all your event bindings and everything else will fail. If this is the case simply remove the line:</p>
<pre>&lt;script src=&quot;http://code.jquery.com/jquery-latest.js&quot; /&gt;</pre>
<p>From the above code.</p>
<p>That should be it, hit me back if you have any feedback, questions, or need some help.</p>
]]></content:encoded>
			<wfw:commentRss>http://dragffy.com/blog/posts/making-codeigniters-profiler-ajax-compatible/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>HTML Helper for generating a country drop-down list in CodeIgniter</title>
		<link>http://dragffy.com/blog/posts/html-helper-for-generating-a-country-drop-down-list-in-codeigniter</link>
		<comments>http://dragffy.com/blog/posts/html-helper-for-generating-a-country-drop-down-list-in-codeigniter#comments</comments>
		<pubDate>Fri, 09 May 2008 12:04:50 +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>

		<guid isPermaLink="false">http://dragffy.com/blog/?p=44</guid>
		<description><![CDATA[Frustrated at having to create my own drop-down country lists in CI I created a helper for it. It can even work with the CI Validation class, so if the form is submitted and fails validation when it is redisplayed the same country is selected as the form was submitted with. Download the file MY_form_helper.php [...]]]></description>
			<content:encoded><![CDATA[<p>Frustrated at having to create my own drop-down country lists in CI I created a helper for it. It can even work with the CI Validation class, so if the form is submitted and fails validation when it is redisplayed the same country is selected as the form was submitted with.</p>
<p>Download the file <a href='http://dragffy.com/blog/wp-content/uploads/2008/06/my_form_helperphp.zip'>MY_form_helper.php</a> and put it in the folder: <code>/system/application/helpers/</code>.</p>
<p>Download the file <a href='http://dragffy.com/blog/wp-content/uploads/2008/06/countriesphp.zip'>countries.php</a> and place that in <code>/system/application/config/</code>.</p>
<p>You will now be able to create drop-down lists of countries in your views like this:<br />
<code>< ?=form_countries( 'country', $this->validation->country, array( 'style' => 'width: 250px' ) )?></code></p>
<p>Ensure that you create a validation rule called &#8220;country&#8221; in your controller and that you are loading the form helper.</p>
<p><code>form_countries()</code> takes three arguments. The first is the name you would like to give the select box, this is required. The second is the country to select by default &#8211; this could be something like &#8216;GB&#8217;, or <code>$this->validation->country</code>, otherwise you can leave it blank. The third argument is any additional properties to give the select box, you can leave this blank, or pass an array. In the example above we also set the width to 250x. The country chosen by the user will be returned to the script as a two-letter ISO country code, if you are validating this then you can set the min and max length values as 2, and accept alphabetical characters only. If using MySQL as your database you will get best performance by creating a column of the type char with a length of 2.</p>
]]></content:encoded>
			<wfw:commentRss>http://dragffy.com/blog/posts/html-helper-for-generating-a-country-drop-down-list-in-codeigniter/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Profiling in CodeIgniter</title>
		<link>http://dragffy.com/blog/posts/profiling-in-codeigniter</link>
		<comments>http://dragffy.com/blog/posts/profiling-in-codeigniter#comments</comments>
		<pubDate>Tue, 06 May 2008 14:56:16 +0000</pubDate>
		<dc:creator>Gabe</dc:creator>
				<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://dragffy.com/blog/?p=40</guid>
		<description><![CDATA[Profiling an application is a great way to see how it is performing. CodeIgniter comes with a profiling class, which you can make calls to from your controllers. However, during development I find profiling so helpful that I want it on all my pages, without having to specifically call it each time. I also want [...]]]></description>
			<content:encoded><![CDATA[<p>Profiling an application is a great way to see how it is performing. CodeIgniter comes with a profiling class, which you can make calls to from your controllers. However, during development I find profiling so helpful that I want it on all my pages, without having to specifically call it each time. I also want to be able to deploy my development site to a production server &#8211; making calls to the profiler throughout the controllers means I would need to edit each and every controller to make sure the profiler wasn&#8217;t active on the live server.</p>
<p>After much searching I discovered a better solution. This allows you to add profiling to the bottom of every page (along with its debug info and SQL query info). When you copy the dev site live you just exclude 1 file, and profiling will be removed totally. All you need to do is create a file called <code>MY_Output.php</code> in <code>system/application/libraries</code> that extends the Output core class, with the following contents:<br />
<code><br />
< ?php<br />
# /system/application/libraries/MY_Output.php<br />
if (!defined('BASEPATH')) exit('No direct script access allowed');<br />
class MY_Output extends CI_Output {<br />
    function __construct() {<br />
        parent::__construct();<br />
        $this->enable_profiler( TRUE );<br />
    }<br />
}<br />
?><br />
</code></p>
<p>This will enable profiling output on all your pages for development and debug purposes. When you copy your site to a production server just make sure you don&#8217;t copy MY_Output.php file. I normally use rsync for copying live and just add: <code>--exclude="MY_Output.php"</code> to the rsync command.</p>
<p>The condition to using the name <code>MY_Output.php</code> is that you left the variable <code>$config['subclass_prefix']</code> in config.php as default. This defaults to <code>$config['subclass_prefix'] = 'MY_';</code>, so if you change it you will need to alter the filename of your new class.</p>
]]></content:encoded>
			<wfw:commentRss>http://dragffy.com/blog/posts/profiling-in-codeigniter/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Protected: CodeIgniter for Rapid PHP Application development</title>
		<link>http://dragffy.com/blog/posts/codeigniter-for-rapid-php-application-development</link>
		<comments>http://dragffy.com/blog/posts/codeigniter-for-rapid-php-application-development#comments</comments>
		<pubDate>Thu, 06 Mar 2008 15:43:14 +0000</pubDate>
		<dc:creator>Gabe</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[CodeIgniter]]></category>
		<category><![CDATA[Frameworks]]></category>
		<category><![CDATA[Information]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://dragffy.com/blog/posts/codeigniter-for-rapid-php-application-development</guid>
		<description><![CDATA[There is no excerpt because this is a protected post.]]></description>
			<content:encoded><![CDATA[<form action="http://dragffy.com/blog/wp-pass.php" method="post">
<p>This post is password protected. To view it please enter your password below:</p>
<p><label for="pwbox-23">Password:<br />
<input name="post_password" id="pwbox-23" type="password" size="20" /></label><br />
<input type="submit" name="Submit" value="Submit" /></p></form>
]]></content:encoded>
			<wfw:commentRss>http://dragffy.com/blog/posts/codeigniter-for-rapid-php-application-development/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>

