I have always been a slow adopter of frameworks. I used to write all my own JavaScript and every PHP app was written from scratch. I liked having the control over the entire project, if something wasn’t working i could easily identify the point of failure because i had a solid understanding over every line of code being executed. After my first experience with jQuery I got right over my hesitations, tho I’m still not a first adopter on every new framework out there.

I’ve been working in CodeIgniter for several months now and have learned a few things.

1. Always have your controllers extend MY_Controller.
If and when the developers of CI decide to change the name of the core controller that all controllers extend you’ll only have to change it in one place. More importantly tho it gives you the ability to keep your controllers a lot cleaner and more narrowly focused. All of our controllers extend one of two custom controllers Public_Controller and Private_Controller (Both of these extend MY_Controller which extends CI_Controller). The Private_Controller handles the authentication so the code is not duplicated in every secure controller. It is not a bad idea (probably a good one) to do the same with your models, you can build in simple update, insert, delete and selects that you’ll have to do anyway.

2. Use Libraries and Helpers.
if you have code that will be used in multiple controllers you need to either put the functions in a helper or create a library to handle it. It’s important. you need to do it. We started using Memcached to help out with page load, and once i wrote it into a library it made creating and managing keys much easier and more reliable as well as simplified integration into new controllers.

3. Use config files.
It took me too long to figure this one out. Initially i put all the config settings in my config/constants.php, it made for easy access to the config variables but inevitably i ended up with a really messy constants.php file. Separating configuration details in config files makes managing and updating them much easier and other developers expect it, and can then implement your code into their CI app.

4. Don’t be afraid to extend the Core.
Extending things like the Log, CI Controller and Router will unleash untold power. That may not be exactly true, but it will feel like it. I overwrote the write_log method in CI_Log and was able to setup custom error logging, while still keeping the stock logging in tact and when i want to implement this custom logging in my application i drop in the MY_Log and the log config file and it’s done.