Archive Page 2



Published September 23rd, 2007 by Jim O'Halloran

links for 2007-09-22

Published September 21st, 2007 by Jim O'Halloran

CodeIgniter and External Resources

There’s been a couple of posts on the CI forus recently about either controllers running twice or external resources (such as images, css, or javscript) not loading. Whenever I’ve run into this problem it’s always come down to issues around the references to the externals. Usually, usage of a relative link rather than an absolute one.

Incorrect referencing causes duplicate controller runs because the browser would load the page, then start pulling down the images, etc and run the application code again. Lets work through an example and see why this happens. If we have the following image tag:

<img src="images/spacer.gif" />

This will try to load http://www.example.com/images/spacer.gif if it’s used on the home page (i.e. http://www.example.com/). Problems begin when we start using the URL to access CI controllers and methods. For example our relative link becomes http://www.example.com/index.php/controller/method/images/spacer.gif when the current page is http://www.example.com/index.php/controler/method/. The browser will attempt to load our image from the incorrect location, resulting in the controller being executed a second time (CI intercepts and handles the request for index.php/controller/method). It won’t result in an infinite loop because the browser will treat the html returned from the second execution as bad image data and discard it. Note: If you use .htaccess to remove the index.php from the URL the same thing still occurs.

The best fix for that problem is to load all external files with a bit of assistance from the URL helper, like so:

<img src="<?php echo(base_url()); ?>images/spacer.gif" />

That will ensure that the images are always loaded from an absolute location. When I implemented this on all of my javascript, css, etc my problem went away.

Watch also for javascript code which loads resources from a relative path, as this will will also be upset by CI’s “fake” directory structure.

Published September 21st, 2007 by Jim O'Halloran

links for 2007-09-20

Published September 10th, 2007 by Jim O'Halloran

Building a Complete CodeIgniter Application

Over the coming weeks/months I’m going to write a series of blog posts describing the construction of a complete AJAX application using the CodeIgniter framework. I’ve chosen to build a multi-user Feed Reader, which I’ll call “Feedignition”. Feed Readers seem to be the new “hello world”, and there’s good feed parsing libraries available which allow us to concentrate on the application itself without having to worry about the myriad of details involved in actually parsing of a feed. That leaves us free to explore a number of topics which will be of interest to anyone building applications with CodeIgniter.

I’ll assume you’re familiar with PHP programming, and have a PHP development environment already set up on your machine, including web server, MySQL database, and so forth.

I’ll post the series in parts as I write it, but I won’t commit to a schedule for new parts. All code in this series (including the final product) is released under the terms of the GNU GPL.

If you’re not subscribed to one of my RSS feeds, check back here for new parts of the series. I’ll update this post wnenever new parts have been posted.

Published September 10th, 2007 by Jim O'Halloran

Building a Complete CodeIgniter Application: Part 1

Over the coming weeks/months I’m going to write a series of blog posts describing the construction of a complete AJAX application using the CodeIgniter framework. I’ve chosen to build a multi-user Feed Reader, which I’ll call “Feedignition”. Feed Readers seem to be the new “hello world”, and there’s good feed parsing libraries available which allow us to concentrate on the application itself without having to worry about the myriad of details involved in actually parsing of a feed. That leaves us free to explore a number of topics which will be of interest to anyone building applications with CodeIgniter.

I’ll assume you’re familiar with PHP programming, and have a PHP development environment already set up on your machine, including web server, MySQL database, and so forth.

I’ll post the series in parts as I write it, but I won’t commit to a schedule for new parts. All code in this series (including the final product) is released under the terms of the GNU GPL.

Lets get started, with part 1!

Basic Configuration

Before we can dive into the application itself we need to get a basic development environment up and running. I’m developing on a Linux machine using Apache 2.2, PHP 5.2, and MySQL 5.0. If you’re on Windows the easiest way to get up and running would be to download XAMPP from ApacheFriends.org. Most of the CI video tutorials skip over this bit and start off where this part finishes up, but preparation is very important so I figure we should start at the beginning.
Continue reading ‘Building a Complete CodeIgniter Application: Part 1′

Published September 8th, 2007 by Jim O'Halloran

links for 2007-09-07

Published September 7th, 2007 by Jim O'Halloran

Thoughts on learning CodeIgniter

Here’s how I went about learning CodeIgniter, I hope it’s of assistance to anyone else trying to do the same. Firstly, it’s difficult to say how long it would take someone to come up to speed with CI, but I’ve done 3 projects using CI now, so my experiences might be helpful. I’ve been developing with PHP on a full time basis for about 2.5 years, and part time for about 3 years before that. I’ve also worked with other (home grown) MVC frameworks before, so when I came to CI, the concepts of MVC and the “right” way to do things in an MVC model were already fairly well ingrained. If you haven’t worked in an MVC style before, it may take you anywhere from few days to a week to fully come to terms with it.

With CI specifically, I spent probably about a day (8 hours) installing CI, and wandering through the directory structure to understand the layout. I also worked through the sections in the manual on CI Controllers and Views to get an understanding of the CI structure. Once I had a handle on those, I looked at Models and the other CI helpers and libraries. Installing BambooInvoice at this point is handy as well because it gives you a sample app to look at and learn from later. I also printed out the entire CI manual, while this has been useful at times, it probably wasn’t as much help as I thought it would be. By this I mean that the manual IS excellent, but it’s more convenient to use and move around in in HTML form, locating things in the printed manual takes longer than it would in HTML form.

After getting familiar with the overall framework I dived right in and began coding my first app. For the first few days I’d say I was about half as productive as I would have otherwise been as I started to learn how things like the validation library worked, how to handle form input the CI way and so forth. Since then I’ve become progressively more productive using CI, and now I find I’m doing things faster and easier with CI than I did before!

So, expect to spend a bit of time on familiarization, how much will depend on your experience both in PHP and other MVC frameworks. Then expect to be somewhat less productive when you first start developing the app, while you come to grips with CI. It’ll take a while, but it will be worth it in the end.

Published September 7th, 2007 by Jim O'Halloran

links for 2007-09-06

Published September 6th, 2007 by Jim O'Halloran

How I use CodeIgniter’s MVC

There’s always some discussion in the CodeIgniter community (especially the Forumsforums) about the MVC model. Usually these questions are asking about the “right” way to do something, or whether something should be in a model, the controller, or even a library. So what I wanted to do in this blog post is explain how I use the MVC framework offered by CodeIgniter and hopefully answer some of these questions.

I should note first up that I’ve developed a few applications in CodeIgniter at this point, and using these principles they all work well, maintain a clean separation between presentation and business logic, and are easy to maintain. What I’m presenting below is by no means the only way to write apps in CodeIgniter, there’s no doubt going to be many many other approaches. However my approach does seem to be slightly different to some members of the CI community. For example, if you watch Derek Allard’s Ajax video, you see Derek returning HTML from his model, something I’d avoid in my own apps. CI is a loose framework, you’re free to use it however you like as long as it gets the job done for you. This is just my personal opinion.
Continue reading ‘How I use CodeIgniter’s MVC’

Published September 6th, 2007 by Jim O'Halloran

Funniest Comment Spam Ever

I hate comment spam, but I found this in my moderation queue this morning… I marked it as spam and junked it, but I thought I’d preserve it here for everyone to see…

hello , my name is Richard and I know you get a lot of spammy comments ,
I can help you with this problem . I know a lot of spammers and I will ask them not to post on your site. It will reduce the volume of spam by 30-50% .In return Id like to ask you to put a link to my site on the index page of your site. The link will be small and your visitors will hardly notice it , its just done for higher rankings in search engines. Contact me icq 454528835 or write me tedirectory(at)yahoo.com , i will give you my site url and you will give me yours if you are interested. thank you

So, he can reduce my comment spam by asking the spammers nicely, and in return I get to spam my home page for him? Wow, seems like a good deal to me! Pity for him Akismet works so well and I never see the majority of my spam :)