Installation of required custom classes
Moderators: tjay, seadap, Rogue4ngel, matthewhayashida
Installation of required custom classes
The component I am developing has several custom classes that are required by both the frontend and adminstration area. Is it recommended to copy the classes to both components/mycomponent and administrator/components/mycomonents or should I reference one from the other?
Re: Installation of required custom classes
If your custom component requires it's own library I would recommend storing the library in only one location. Either in the frontend or in the administrator is up to you but I would recommend storing your library in administrator -> components -> com_yourcomponent -> libraries
You would then import your library in the entry point file of your component.
If the libraries are in the frontend you can use the constant JPATH_COMPONENT_SITE.
If the libraries are in the backend you can use the constant JPATH_COMPONENT_ADMINISTRATOR.
The contsant, JPATH_COMPONENT, will give the component directory the file is currently in. So, for example if calling the constant from the frontend entry point file the path will be for the frontend of the component but if calling that constant from the entry point file of your component in the administrator backend the path will be for the backend component directory. In use it would be this...
Substitute either JPATH_COMPONENT_SITE or JPATH_COMPONENT_ADMINISTRTOR for JPATH_COMPONENT if you would like.
I hope that was clear but if not, let me know.
You would then import your library in the entry point file of your component.
If the libraries are in the frontend you can use the constant JPATH_COMPONENT_SITE.
If the libraries are in the backend you can use the constant JPATH_COMPONENT_ADMINISTRATOR.
The contsant, JPATH_COMPONENT, will give the component directory the file is currently in. So, for example if calling the constant from the frontend entry point file the path will be for the frontend of the component but if calling that constant from the entry point file of your component in the administrator backend the path will be for the backend component directory. In use it would be this...
Code: Select all
require_once(JPATH_COMPONENT.DS.'libraries'.DS.'customlibraryfile.php');
Substitute either JPATH_COMPONENT_SITE or JPATH_COMPONENT_ADMINISTRTOR for JPATH_COMPONENT if you would like.
I hope that was clear but if not, let me know.