skip to content

Tips for Getting Started Building an Application Using Code Igniter

November 06th, 2006

When I originally released BambooInvoice I learned a lot about trying to code for a site specific goal, and coding for a mass audience. I originally wrote these tips on the Code Igniter forums, but since I was recently asked for advice again, I thought I'd repost them here. The original thread is still active.

Since I released BambooInvoice I've received a number of interested emails from developers looking for tips on getting started building an application using code igniter that you intend to widely distribute. Here is a small collection of useful processes.

They are primarily aimed at people who will be building, and then sharing the application with others, but many of these tips are great even for a single website whose code you never intend on showing to anyone.

  1. If you intend on using .htaccess to remove index.php from your URL, make sure it works before you start building your app. Great tips for that on this forum thread, but here's a good all around file that works for most people. RewriteEngine on RewriteRule ^$ /index.php [L] RewriteCond $1 !^(index\.php|img|css|js|robots\.txt|favicon\.ico) RewriteRule ^(.*)$ /index.php/$1 [L]
  2. Now that your .htaccess file is working - cripple it by renaming it to "temp.htaccess". You can restore it when you are finished, but by not having it available while you build, it will make visible some errors that it might cover up (I had a redirect error that I didn't catch until .htaccess wasn't used). Many people using your code won't have the knowledge or ability to use .htaccess, you want it to work for everyone.
  3. Don't modify the Code Igniter core. This is of course perfectly fine if you are the only user, but if you distribute your code people will upgrade to the new version of Code Igniter, and your modifications won't carry through.
  4. Learn to love base_url() and site_url(). Use them - a lot. When I started with Bamboo I simply referenced image and css folders with an absolute path (<link href='/css/style.css' />). This worked fine for me, but when other people wanted to install it into non-root folders, all the paths broke. If I had coded with base_url() and site_url() that would have been avoided.
  5. Abstract your work and make them available as plugins to the CI community. Implemented a neat feature for your site? Make it a plugin. Even if you think its too simple, share it anyways.
  6. Use conventions. In Bamboo, the views directory is structured such that every controller has a folder, and every class has a view page. There are certainly other ways to do it, but by following that simple convention, other developers can quickly and easily find the file they are looking for.
  7. Bonus tip: If you participate in the community, try to help others as well as yourself. If you have 64 posts, and all of them start with "I need help with" then you aren't giving back. Try answering other people's questions as well as asking for help with yours.

Have another great tip for development? Share it here!

This entry was made on November 06th, 2006 @ 17:19 and filed into CodeIgniter, How-To.

Comments

Yannick wrote on November 06th, 2006 @ 23:57

Pretty good tips Derek, thanks for sharing. :) Will certainly do my best to offer more assistance in the community where possible.

Matthew Pennell wrote on November 20th, 2006 @ 21:56

Good tips; I’m guilty of ignoring #4 when using CI to build websites rather than apps, but I should really get into the habit of using it.

Some other things I’d add:

8. If you plan to distribute the finished app for other developers to customise, consider using the Parser library to make it easier for non-techies to understand what is going on in the views.

9. PLAN! Document the site architecture, URL schema, etc. before you start; you don’t want to have to go back through all your controllers because you suddenly realised the page title needed to be in the data array…

Derek wrote on November 21st, 2006 @ 0:13

That’s a great point Matthew.  Not understanding what is loading when, is probably the main problem we have when working with other people’s apps.

And since we’re sharing here, I’m guilty of ignoring your #9 sometimes ;) I think we all get excited about the prospect of coding that using pencil and paper (or whatever) just isn’t all that sexy.

Post a Comment

Sorry, comments are automatically closed after 45 days, or sooner if one entry gets targetted by spammers. Why not contact me directly?