4

My component is using phpExcel library; I put it into /libraries/phpexcel/Classes. This is an independent (and quite big) library, so I thought, that it would be wise to tell the admin where to put it before component installation. And in the install script of the component check the existence of the lib.

I import the library using this code:

jimport('libraries.phpexcel');
//Include PHPExcel classes
JLoader::import('phpexcel.Classes.PHPExcel');
JLoader::import('phpexcel.Classes.PHPExcel.IOFactory');

Is it the correct way to use an external library?

1 Answer 1

5

If you're only ever using a library within a single component then there's no reason not to include it in a folder in the component - this is the way that distributed components will generally handle it. That being said, you can put anything you like in the libraries folder and Joomla won't mind, the issue is how you go about loading the classes. Joomla allows you to autoload via prefixes or namespaces like this:

https://docs.joomla.org/Using_own_library_in_your_extensions

But if you wish to use a composer autoloader for external packages with your component you may be interested in this approach here:

How to add a composer package without modifying the core composer.json file

Hopefully one of these approaches will suit.

1
  • I added the code I use for importing.
    – user4035
    Feb 4, 2018 at 1:05

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.