0

I am trying to incorporate an external application as a library within Joomla which I have done before on a couple of occasions, however in this case there is a single .php file with about 20 classes and I am starting to think it is not possible to handle this in Joomla.

When I try to use a Class it comes back as not found.

My previous efforts haves always been a single file containing a single class of the same name as the file it resides in.

In the non Joomla environment this application uses a simple Include statement but in my attempts I am using Jloader to register the Namespace, like I have done before, but everything I have read all seems to expect a one to one relationship between the filename and the class name.

Am I trying to do the impossible?

I could split the single file into individual files/classes but I would prefer not too if I don't have to.

1 Answer 1

1

Just curious, but what's the issue with breaking it up? Seems to me it's much better programming practice and better for tracking down issues to not have to dig past 17 other classes to find that one that's causing a problem, so I'm curious what the reasons might be for not doing that.

Aside from that, I think the syntax you're after is:

Jloader::register(classname, pathToFile);

for example:

JLoader::register("MyExtraSpecialClass", JPATH_SITE . '/components/com_mine/library/fred.php'

Repeating the same file for every class in it (and remembering to add whatever namespacing there might be for the class name). Didn't that work for you?

2
  • Thanks for answering. Maintenance was the main reason for not wanting to split things up. When the vendor comes out with a newer version I would have to compare old single file with the new single file and then fit the changes into each file I have created. I have since managed to get the single file working, it is an ugly hack though, therefore I have started breaking the classes into individual files which is much nicer to manage and I will deal with the maintenance when it happens.
    – Irata
    Jan 30, 2020 at 19:57
  • OK, did the calls above help, or are you still having this issue? If you are, what, specifically, is happening?
    – Arlen
    Jan 31, 2020 at 15:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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