Quantcast
Channel: Suburban Glory
Viewing all articles
Browse latest Browse all 101

Resources for learning CodeIgniter

$
0
0

It could be argued that CodeIgniter is the most popular Open Source PHP framework around. It certainly features heavily on developer and designer sites like Forrst.

Written in OOP code it takes a liberal approach to the Model–view–controller (MVC) architecture that underpins all modern PHP frameworks, and it has a very active and supportive community around it.

codeigniter logo

I put aside some time during the winter to learn CodeIgniter. Anybody who has prior experience of using OOP PHP should pick up most of the code within a couple of weeks, but I went further and created my own Content Management System which I called CodeSharp.

It was a fun but lengthy exercise as it stretched on further that I expected not least because of the JavaScript and AJAX I added to the administration section, but it pays dividends to recreate the wheel if you are trying to fully understand a new web technology.

Learning Resources

There are a number of tutorials that I used while learning this MVC framework, the most important of which were the Nettnuts+ online CodeIgniter from Scratch video series. Easy to follow and free to watch they cover most of the code basics. Just using this online series alone will provide a solid foundation to your learning process.

Nearly all available resources concerning CodeIgniter are for the older 1.7 version so the least confusing option for me was to pick up the framework using 1.7. Afterwards, I updated the code from 1.7 to the current 2.1. The backwards compatibility between the two major versions was excellent and it required very little code change. At the time of writing the next version will be 3.0 and it is currently in development stage.

The second must-use online resource is the CodeIgniter User Guide, available for both versions 1.7 and 2. I think this is the most easy to use and comprehensive online guide for any web technology that I have ever come across. Perhaps this is because a private company – Ellis Labs – is behind the entire initiative and so is better organised than other Open Source projects I have used in the past. As opposing examples, php.net and the jQuery documentation contains valuable information but they are non-user friendly and need to rewritten from the ground up.

I brought two books on the Packt imprint: CodeIgniter 1.7 by Jose Argudo Blanco & David Upton and CodeIgniter 1.7: Professional Development by Adam Griffiths. They were useful but the beef I have with Packt is that their books lack the depth that you would find in an O'Reilly or Apress publication. The feeling after finishing a Packt book is akin to eating a sandwich when you was hoping for a three-course meal.

Some CodeIgniter feedback

If anybody is looking for a PHP framework to learn then I would certainly recommend CodeIgniter. Below are elements of the script I liked, and some which I didn't.

Pagination class: Pagination is one of the more trickier server-side coding problems to solve. Using the CodeIgniter pagination class makes this challenge dead easy with typical code in the controller class looking like this:


$config['base_url'] = site_url("content/index/");

$config['total_rows'] = $this->content_model->find_content_rows($visible = true);

$config['per_page'] = 3;

$config['num_links'] = 2;

$config['uri_segment'] = 3;

$this->pagination->initialize($config);

Encryption class: If want to be 100% sure of securing your database in the event of a cracking, then using PHP Mcrypt is the only feasible solution. Hashing using SHA1 alone will not secure your data to the necessary unbreakable level. CodeIgniter has its own encryption class that uses PHP Mcrypt, hashing, base64 encoding and adds cipher noise to protect against Man-in-the-middle attacks.

The encryption class, while being secure, increases the size of the encoded messages 2.6 times the size of the original message – according to the documentation. I found that it was increasing the size of my data by as much as eight or nine times. If you use the encryption class keep an eye on this expansion because if the database field isn't big enough then the encrypted information becomes unusable.

The Database class: I used the Active Record Class (ARC) for all database queries as I prefer the placeholder method of inserting database info rather than escaping data. As I am already using PDO I'm not sure whether the ARC brought anything new to the table, and it will be slower than using straight inbuilt PHP objects.

Form helper: I used the form helper in my views but it never saved any time as I am already more than familiar with correct HTML form markup. Perhaps its useful if you are working on a collaborative project and need to make sure that the code is consistent throughout.

Image manipulation class. I wasn't happy with the quality of the image thumbnails it was producing so I used the Imagine script instead.

Typography class: The auto_typography() class is really useful for formatting non-HTML text taken from the database. On previous PHP builds I was using HTML Purifier for the same functionality.

Routes / _remap: This is a sane way of creating human and search engine friendly URLs without pissing around with regex in the .htaccess file. It took a bit of tinkering to work out the correct code, but it is the most sensible method for altering a URL.

Conclusion

I hope above has given you some enthusiasm to try out CodeIgniter if you haven't already. If you want to write safe, well-tested PHP code then this certainly is a framework that you will need to investigate. It is not the only PHP framework but it is one that is widely used in commercial development.

Footnote: PHP queen Lorna Jane Mitchell has just written a short piece on the net magazine site called PHP: land of a thousand frameworks and which is worth reading as a supplementary article to this post.


Viewing all articles
Browse latest Browse all 101

Trending Articles