CodeIgniter 3.0 and How I use it!

So, we recently upgraded our framework version from 2.2.3 to 3.0.0 at Seenit.in. The latest version is more around bug fixes and making the session library more secure. There is a huge debate these days over other frameworks, mostly Laravel vs CodeIgniter. Majority of the people are of the opinion that CI is now the granny PHP framework and we should be moving towards younger and better frameworks. But I’ve been a big fan of CodeIgniter from the beginning and don’t want to lose hope all that soon.

Screen Shot 2015-05-28 at 9.49.44 AM

So after upgrading CI to 3.0, I decided to change some of my practices so that I gradually move towards a more modern style of coding. Here are some of my changes:

1. config_item() : This function was available in the previous version as well but I only found about it after upgrading. ( from the up-gradation steps ) I think it is a very handy shorthand for $this->config->item() function. Although the official user guide says that the latter is the preferred method over the earlier, but it also says that there is no harm in using it for retrieving single key values. So unless we are dealing with multiple config files with name conflicts, we should be fine.

2. [] for array definition : This shorthand is pretty handy in my opinion. ( not exactly a 3.0 change ). Traditionally in documentations and online tutorials, arrays have been used using the array()  syntax for both indexes and associative types. But in my opinion a

$temp = [ '1' => 'apple', 'two' => 'orange']

and

$arr = ['mumbai', 'delhi'];

are much more easier to type. The only limitation here is that this syntax was introduced in PHP 5.4. So as long as we are using a PHP with a higher version, we should be good.

3. $config[‘reuse_query_string’] = true : This new config value in the pagination library in 3.0 has been a huge help. So the way pagination links work in CI is that they append the offset to the url itself. So page 2 of the url http://abc.com/list will be http://abc.com/list/40 where 40 is the number of items you show on each page and url for page 3 will be http://abc.com/list/80 and so on. But if my page has some query params which I want to retain, like for the url : http://abc.com/list?q=php, the pagination url will ignore the GET params, like so : http://abc.com/list/40. But with the above config variable this is now possible. http://abc.com/list/40?q=php