Matt Matt - 6 months ago 44
PHP Question

CodeIgniter: difference between loading a helper in a controller file vs config

I was wondering if there are any difference between

function __construct()
$this->load-> helper('file');

this inside one of my controller file vs

$autoload['helper'] = array('file');

in terms of best practices.

For the 2nd option, would it slow down the application just a little bit because these helper functions may be used where it may not be needed (say half the application).


The difference? If you have a small website, it's negligible. But if you want to squeeze your website to the last bit for performance, it's better to load those helpers only where they are needed. Loading them is still an I/O request, several function calls and includes - which is overhead, noticeable in large scale.

codeigniter is focused on speed, that's why most of the helpers you rarely need in a page are loaded optionally (not to mention an optional model).