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.
- 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] - 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.
- 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.
- 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.
- 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.
- 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.
- 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.

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.