Codeigniter Tips and Tricks
CodeIgniter is very easy me to install. It requires PHP version 4.3.2 or newer and one of the following databases: MySQL, MySQLi, MS SQL, ODBC, Oracle, Postgre or SQLite. Most people (myself included) use MySQL, but it’s good to know it supports some of the other big names.
Best of all, CodeIgniter is available as freeware so there is no charge for downloading and using this software! Even though EllisLab Network offers the CodeIgniter software free of charge, they still provide user forums, a wiki and a bug tracker to help support the application and its community of users.
If you are looking for the best way to streamline your PHP web development process, then CodeIgniter may be just the application that you need – I know it was for me.
- Always try to follow the MVC Structure as this is the basic for all frameworks and ofcourse with CI. Always write your Logic in Controllers , HTML in Views and Databases queries in Model.
- Whenever you start with CI project , always start with defining your project’s site configuration as this helps you to be more clear about your site configuration, with CI you can start with config.php file in your application/config folder as this is what you define your site’s base url which will be used while coding throughout the project and also you can set other options like language, charsets etc.
- Always define your common libraries , models, helpers that will be required throuphout your site in application/config/autoload.php file as this helps you to avoid the overhead for including all common libraries , models, helpers everytime you write a new controller
- Always use your controller’s and model’s class name same as your filename as because this is rule for CI and also it makes it easy to go through your controller or models.
- Always use CI’s own set of libraries and helpers as they are more secure and can save our time to code our own security code though they are available with us.
- For form validations always use CI’s form validation libraries as it has in built XSS and MySql injection vulnerability prevention ability.
- Never keep Scaffolding enable on live site.
- Always escape your user input that you are passing to your database , this helps you to prevent unwanted attacks on your database. CI has it’s own escapea function.
- Always follow the CI style commenting as it is more descriptive and clear.
- Always keep your admin files and frontend files in different folder’s as it easy to differiantiate and work. This is only applicable for views and models.
- Use Activation Records functions for immediate and small database requests like count number of rows , select records etc as this saves our time to write long queries unnecassarily.
- To boost your site performance always use Query caching available in CI , your database usage can effectively be reduced to zero for any pages that have been cached.
- Always read the PHP style guide in CI user’s guide before if you are new to CI, you can find this in CI user’s guide
- And last but not least never use Short tags <?=?> as this may be not allowed in higher versions of PHP ( 6.x)