Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
293 views
in Technique[技术] by (71.8m points)

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

I was wondering if there are any difference between

function __construct()
{
    parent::__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).

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...