Archive Page 2
This is the second installment in a series called “Building a Complete CodeIgniter application”. In this series I’ll walk readers through 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.
In the last part of this series we created the foundations on which we’ll build the FeedIgnition aggregator. We installed the basic CI framework, and set up our database connections. When we finished up we have an app that did absolutely nothing, every possible URL resulted in a 404 error. However, this was necessary to give us a base on which we can build our feed reader, now we’ll get down to the nuts and bolts of actually building an app in CodeIgniter. Before we get started, you’ll need to make sure you’ve worked through part 1 and have CI + a database ready to go.
Continue reading ‘Building a Complete CodeIgniter Application: Part 2′
-
Joel Spolsy’s example functional spec for a fic tional “whattimeisit.com” service. Wonder if I should implement this as a sample CodeIgniter app
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.
-
The jQuery UI library looks like it could save me a heap of work, very handy.
-
Very well done video explaining the utility of Wikis.
-
Plain english explanation of social bookmarking sites like delicious.
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.
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′
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.
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’