Take the 2-minute tour ×
Joomla Stack Exchange is a question and answer site for Joomla! administrators, users, developers and designers. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 2 down vote accepted

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

Mycomponent.php

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.

share|improve this answer
    
I like this as a general solution, especially given JLoader is lazy. Accepted :) –  codinghands Jul 22 at 7:35
    
Awesome! Thanks for helping me break 200 rep! –  Mathew Lenning Jul 22 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 :-)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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