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.
Archive for PHP
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).



