In the process of keeping websites secure, you can end up with really long strings. If this is generated in the code and saved to sessions/cookies/database, this isn’t a huge problem. However, if you need to publish such an encrypted string (for instance, in an account creation confirmation URL), having massive strings not only can be a problem it also looks unprofessional. Of course, there are plenty of URL abbreviation systems out there (bit.ly and tinyURL.com to name but two), but a lot of the time you want to keep it within your own domain. This is where my abbreviation model comes in handy.
Archive for Articles
CodeIgniter ActiveRecord Order by Field
Following on from my post about how to extend the CodeIgniter database library, I’ve had to to find a way of ordering database results by the values in an array. This is particularly useful if you’ve got an enum field or have specified values in a particular field and then want to output it in a particularly order. My magical order_by_field() method solves this problem.
Advanced Email in CodeIgniter
Sending emails is one of the biggest challenges for a website. As well as making sure they’re secure, you want to ensure that no emails get lost. Since the British Companies Act 2006 made email a legally-recognised form of communication, you also want to ensure that you know what is being sent out in your name. The biggest problem I’ve had is where a script has died when it should have sent an email (usually caused by the pesky Sendmail) and just leaves users waiting for their emails ad infinitum. I’ve also had times where the server has had a limited number of emails it can send per day/hour. This is my attempt to solve these problems.
Extending the CodeIgniter Database Class
In the CodeIgniter user guide, it says that the Database class can’t be extended. Which is a real pain, because it would be useful if it could be. Well, lo and behold, the user guide is telling fibs. The Database class can be extended. And, what’s more, it’s fairly easy and is not a nasty hack either.
CSV Output in PHP
Comma separated values (CSV) files are a really useful way of outputting data to display in spreadsheet programs such as MS Excel. However, they can be a bit tricky to output and get all the headers output. So, here’s a simple class to do it.
XML to PHP Parser
XML is one of the most useful things out there and a great way of extracting data from another website. Unfortunately, PHP can be a bit of a pain in parsing it into something usable. The SimpleXML class has made things easier, but I prefer working with data in arrays rather than in objects which SimpleXML doesn’t really do. I’ve written a library that parses SimpleXML into a PHP array.
Facetted Solr Queries in CodeIgniter
This is a follow on to my earlier post on my Apache Solr library for CodeIgniter. If you’ve not read that, that’s where you need to start. To get your head around it, facetting is similar to MySQL’s aggregate functions (but with so much more). A good overview on what facetting is comes from David Smiley’s book on Solr (a very useful book – get it!):
Faceting, after searching, is arguably the second-most valuable feature in Solr. It is perhaps even the most fun you’ll have, because you will learn more about your data than with any other feature. Faceting enhances search results with aggregated information over all of the documents found in the search to answer questions such as the ones mentioned below, given a search on MusicBrainz releases: Read more
CodeIgniter Solr
First things first, Apache Solr is brilliant. It’s a branch of the Apache Lucene search project, and gives you blindingly-fast, scored search results. Or, as they say themselves…
Solr is the popular, blazing fast open source enterprise search platform from the Apache Lucene project. Its major features include powerful full-text search, hit highlighting, faceted search, dynamic clustering, database integration, and rich document (e.g., Word, PDF) handling. Solr is highly scalable, providing distributed search and index replication, and it powers the search and navigation features of many of the world’s largest internet sites.
There are some drawbacks to this though. First, as it’s a Java server, you have to run it on Jetty or Tomcat. Secondly, the Lucene syntax is a bit tricky to get your head around and get right. Thirdly, with the exception of the Apache’s PHP-Solr-Client, there’s not much information out there on putting into PHP. Until now…
CodeIgniter Registry
A registry is one of the most useful things in any MVC program – it allows you to assign variables, arrays and objects in a similar way that the irksome global variable used to. Surprisingly (and annoyingly) CodeIgniter doesn’t have a registry. A good description of a registry is on the Zend website:
A registry is a container for storing objects and values in the application space. By storing the value in a registry, the same object is always available throughout your application. This mechanism is an alternative to using global storage.
Codeigniter RESTful URL
This script is an extension of the input library to allow parsing of RESTful URLs (one of the more useful features of Zend). RESTful URLs are similar to $_GET URL’s (/index.php?var=value) but are just written out in a more SEO friendly way (/var/value).



