2

I have an extension that is using autoloader to import helpers.

Everything works well in localhost development environment but in the live server the classes are not loaded. I get the error "Fatal error: Class 'MYExtensionText' not found"

1) In components/com_myextension/myextension.php I have this code:

JLoader::import('MYExtension', __DIR__ . '/helpers');

2) In components/com_myextension/helpers/myextension.php I have this code:

JLoader::discover('MYExtension', __DIR__);
JLoader::registerPrefix('MYExtension', __DIR__);

3) So, I expect that this classes are autoloaded in components/com_myextension/helpers/

myextension.php / MYExtension 
text.php / MYExtensionText
model/list.php / MYExtensionModelList

This WORKS FINE in localhost (mamp with php 5.5) but does not work in the server, using CentOS 5 with php 5.4.

Any ideas?

  • Could you try adding var_dump(__DIR__); to components/com_myextension/myextension.php on both your localhost and live host. Would like to know if the results are the same – Lodder Aug 12 '15 at 10:41
  • Hello Lodder I did it, the output is the absolute path to the file folder in both environments – xavip Aug 12 '15 at 11:02
  • Hmm, If the paths are exactly the same then I'm not sure what the issue could be. Could you possibly try replacing __DIR__ with JPATH_ROOT . '/components/com_myextension/helpers/' – Lodder Aug 12 '15 at 14:30
  • Tried JPATH_COMPONENT . '/helpers' and neither works. No errors other than "Fatal error: Class 'MYExtensionText' not found" – xavip Aug 12 '15 at 17:07
2

I found the solution:

JLoader::import('myextension', JPATH_COMPONENT . '/helpers');

Please note the lower case!

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.