I'm developing a Joomla 3.X component and need to register a few classes using:

JLoader::register('MyClass', '/path/to/MyClass.php');

What is the 'best practice' location for including these calls? Within the __constructer of the controller, the view, the model, or elsewhere? Or does it not really matter?

2 Answers 2


This is just my personal preference, but I register autoloading in the extension entry file.


Since this file is always initiated before everything and registering with JLoader doesn't have any significant performance drawbacks, it helps prevent common issues.

Like not registering before initializing a class. Plus if you move something you don't have to try to remember where you registered it.

  • I like this as a general solution, especially given JLoader is lazy. Accepted :) Jul 22, 2014 at 7:35
  • Awesome! Thanks for helping me break 200 rep! Jul 22, 2014 at 8:05

I usually do it depending on where I need it. If I need the class only in a particular view, I just register it in the view. If I need it in most code anyway, I register it in my main controller.

It doesn't really matter as long as you do it prior to using the class :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.