<?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>Scott Blaine &#187; codeigniter</title>
	<atom:link href="http://scottblaine.com/tag/codeigniter/feed" rel="self" type="application/rss+xml" />
	<link>http://scottblaine.com</link>
	<description>Omaha web developer</description>
	<lastBuildDate>Wed, 12 Oct 2011 01:00:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Making CodeIgniter&#8217;s Pagination library play nice with jQuery</title>
		<link>http://scottblaine.com/making-codeigniters-pagination-library-play-nice-with-jquery</link>
		<comments>http://scottblaine.com/making-codeigniters-pagination-library-play-nice-with-jquery#comments</comments>
		<pubDate>Tue, 23 Jun 2009 01:00:28 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[codeigniter]]></category>

		<guid isPermaLink="false">http://scottblaine.com/?p=249</guid>
		<description><![CDATA[I&#8217;m back, and despite the fact that I haven&#8217;t posted in a bit I&#8217;ve been accomplishing quite a bit on the site &#8230;or maybe not. You see, I started keeping track of the hours I&#8217;ve been spending working on the site. Over the last 6 days I&#8217;ve put in 11 hours on the site. That&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m back, and despite the fact that I haven&#8217;t posted in a bit I&#8217;ve been accomplishing quite a bit on the site &#8230;or maybe not. You see, I started keeping track of the hours I&#8217;ve been spending working on the site. Over the last 6 days I&#8217;ve put in 11 hours on the site. That&#8217;s a pretty good amount of time I&#8217;ve put in, actually, considering that my goal is to put in at least 8 hours (the equivalent of one work day) a week on the site.</p>
<p>On the (perhaps) not so good side, the majority of that time has been spent implementing pagination on the search results page. You would <em>think</em> this would be incredibly easy considering that <a title="CodeIgniter's Pagination Class" href="http://codeigniter.com/user_guide/libraries/pagination.html">CodeIgniter has a Pagination class</a>. It shouldn&#8217;t take me approximately 8 hours, right? Well, apparently it does when you&#8217;re trying to use AJAX to handle your pagination. I was even perfectly willing to accept a complete hack for a solution, but alas, anything I tried to do to cobble together a fix for one issue only introduced another issue somewhere else.</p>
<p>Eventually jQuery came to my rescue. In the configuration for Pagination I set the base_url to &#8221; (an empty string) so that the href on the pagination links would contain only the number for the search results. Then I set up jQuery to find all of the anchor links in my paging div, stop the normal link function, and call my function to load in the search results. The jQuery code came out like this:</p>
<pre>
$(document).ready(function(){
  $("div.paging &gt; a").click(function(e){
    // stop normal link click
    e.preventDefault();

    $('div#search_results').load("/search/get_results/"+$(this).attr("href"));
  });
});
</pre>
<p>This is still something of a hack as I&#8217;m basically creating fake href values for the anchor tags, but whatever, it works! I can come back later and fix it. At this point hacks are okay. Speed is much more valuable than perfectly elegant code as I want to find out if my idea is solid before investing oodles of time in it.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottblaine.com/making-codeigniters-pagination-library-play-nice-with-jquery/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Form validation callbacks and private functions</title>
		<link>http://scottblaine.com/form-validation-callbacks-and-private-functions</link>
		<comments>http://scottblaine.com/form-validation-callbacks-and-private-functions#comments</comments>
		<pubDate>Tue, 02 Jun 2009 01:00:02 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://scottblaine.com/?p=149</guid>
		<description><![CDATA[If you&#8217;re familiar with CodeIgniter you probably know about callbacks within form validation. Callbacks allow you to do your own validation of fields. For example, if you want to verify if a username is unique then you could create a username_check function to validate the field. You add the callback rule like this: $this->form_validation->set_rules( 'username', [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re familiar with CodeIgniter you probably know about <a title="Form Validation" href="http://codeigniter.com/user_guide/libraries/validation.html">callbacks within form validation</a>. Callbacks allow you to do your own validation of fields. For example, if you want to verify if a username is unique then you could create a username_check function to validate the field. You add the callback rule like this:</p>
<pre>
$this->form_validation->set_rules( 'username', 'Username',
  'trim|required|callback_username_check' );
</pre>
<p>And then create a matching function like this:</p>
<pre>
function username_check( $username )
{
  // some code
}
?>
</pre>
<p>However, as this is currently implemented someone could access your function as a page at a URL like example.com/index.php/login/<strong>username_check</strong>/ if they guessed the function name. While that may not have any ill side-effects, it&#8217;s probably just as well if no one can access the function besides you.</p>
<p>In come <a title="Controllers" href="http://codeigniter.com/user_guide/general/controllers.html">private functions for controllers</a>, which allow you to create a function like this:</p>
<pre>
function _utility()
{
  // some code
}
</pre>
<p>And if you try to access the function via a URL, like example.com/index.php/login/<strong>_utility</strong>/, you&#8217;ll get a 404 (page not found).</p>
<p>You probably see where I&#8217;m going with this. If you create your callbacks as private functions, no one will be able to access the callbacks as pages. It&#8217;s quite simple to do. You add an underscore before your callback function name:</p>
<pre>
function _username_check( $username )
{
  $valid_username = TRUE; // You would perform some kind of check on the field here

  if ($valid_username == FALSE)
  {
    $this->form_validation->set_message('_username_check', 'The username you have provided is not valid.');
    return FALSE;
  }
  else
  {
    return TRUE;
  }
}
</pre>
<p>And then add an underscore in your callback rule (note the two underscores after callback):</p>
<pre>
$this->form_validation->set_rules( 'username', 'Username',
  'trim|required|callback__username_check' );
</pre>
<p>Done!</p>
]]></content:encoded>
			<wfw:commentRss>http://scottblaine.com/form-validation-callbacks-and-private-functions/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Authentication with CodeIgniter</title>
		<link>http://scottblaine.com/authentication-with-codeigniter</link>
		<comments>http://scottblaine.com/authentication-with-codeigniter#comments</comments>
		<pubDate>Sat, 30 May 2009 01:00:08 +0000</pubDate>
		<dc:creator>Scott</dc:creator>
				<category><![CDATA[development]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[redux]]></category>

		<guid isPermaLink="false">http://scottblaine.com/?p=140</guid>
		<description><![CDATA[Having finished the registration process, I realized I needed some way to keep people logged in, let them log in, log out, retrieve their password, possibly have some kind of email validation, etc. All sorts of things. I started looking through the CodeIgniter user guide and about they closest things they have is the session [...]]]></description>
			<content:encoded><![CDATA[<p>Having finished the registration process, I realized I needed some way to keep people logged in, let them log in, log out, retrieve their password, possibly have some kind of email validation, etc. All sorts of things. I started looking through the CodeIgniter user guide and about they closest things they have is <a title="CodeIgniter's Session Class" href="http://codeigniter.com/user_guide/libraries/sessions.html">the session library</a>. While you could use it to track if a user is logged in, that&#8217;s about the extent of the value it would provide to you.</p>
<p>At first I looked for ways that I might be able to at least run checks on pages to see if a user is logged in or not. It turns out that&#8217;s not terribly difficult (once you figure out how to do it). You need to <a title="Authentication with CodeIgniter - David Winter" href="http://davidwinter.me.uk/articles/2009/02/21/authentication-with-codeigniter/">create your own authentication controller</a> for use with pages where you want to check if the user is logged in. Cool, that works. I could throw the log in/log out functionality in easily enough, but resetting passwords and validating email addresses would be a whole different matter.</p>
<p>That&#8217;s when I decided that I should start looking for a user-contributed authentication library. The CodeIgniter Wiki has <a title="CodeIgniter Authentication Libraries" href="http://codeigniter.com/wiki/Category:Contributions::Libraries::Authentication/">a nice list of them.</a> As I started looking through them and all their various features I realized I should come up with a list of the features that I needed to have. Here&#8217;s what I was looking for in a library:</p>
<ul>
<li>Good coding practices</li>
<li>Good documentation</li>
<li>Small number of files</li>
<li>Database implementation that&#8217;s not complex</li>
<li>Login using username or email address</li>
<li>Emails for lost passwords</li>
<li>Automatic login</li>
<li>Hashing of passwords</li>
<li>Maximum number of failed login attempts</li>
<li>Emails for activation (nice to have)</li>
<li>reCAPTCHA support (nice to have)</li>
</ul>
<p>Not too harsh, right? Unfortunately most of the libraries ended up being too large, too simple, or completely lacking in documentation. It was hard to find a library that fit somewhere in the middle. I did find one library that might meet all of my requirements, and if not, it&#8217;s awfully close: <a title="reduxauth" href="http://code.google.com/p/reduxauth/">Redux 2 (beta)</a>. It has all of the functionality I want, it doesn&#8217;t contain a crazy number of files, the database is simple and well thought out, there&#8217;s a complete sample application that makes use of the library, and more. I&#8217;m going to give it a try and comment in my next post on how well it works.</p>
<p>I should also mention in the course of my search I came across <a title="What Code Igniter authentication library is best? - Stack Overflow" href="http://stackoverflow.com/questions/346980/what-code-igniter-authentication-library-is-best">an excellent post on Stack Overflow regarding authentication libraries for CodeIgniter</a>. There&#8217;s a lot of great discussion on that page and Redux was also listed there as being one of the better solutions available.</p>
]]></content:encoded>
			<wfw:commentRss>http://scottblaine.com/authentication-with-codeigniter/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

