• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
always check if a class has been previously loaded ?

#1
Hi,

Can we use $this->load (library, model, or other loadable class or item) without making a check if that item has been already previously loaded with $this->load->is_loaded() ?

Is it the same for when using $this->lang-load ?

thanks.
Reply

#2
CI (in Loader class) already makes a check and won't load something if it's already been loaded so no need to check it manually. It will just return the previously loaded instance if it's already been loaded instead of reloading it.
Reply

#3
Generally, $this->load->xyz() and $this->lang->load() are fairly intelligent about checking whether something has been loaded. For example, if you're loading a language file which has previously been loaded, it won't be reloaded. However, if you're loading a language file which was loaded previously under a different language, it will reload the file for the new language.

However, you may be able to perform a more efficient check in your code than that used by the method in question and save yourself a small amount of time for subsequent calls to load the same model or library. It's not necessarily worth the effort, because $this->load->model() and $this->load->library() should never cause any problems by being called for a model or library which has already been loaded, but it could make a small difference in extreme cases.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.