I'm developing a component that is targeting Joomla 3.9+. The code is not using the legacy classes and is instead using the new namespaces. The component will duplicate much of the functionality from the admin side so I'd prefer to share code and Sql queries where applicable. What is the best way to do this moving forward? Should I use the admin model on the site? Should I create a library or namespace? What is the preferred way to do this with the approaching 4.0 release? Also, is there a good way to share ui elements and forms between the two?

1 Answer 1


Should I use the admin model on the site?

That's what I've done in the past. Historically I've used admin models on the site side of things by doing something like this:

$controller->addModelPath(JPATH_COMPONENT_ADMINISTRATOR . '/models');

These days the JLoader supports PSR-4 style namespaces. If I were to build a component from scratch today, that's what I would use. Something along the lines of:

JLoader::registerNamespace('App', JPATH_COMPONENT_SITE, false, false, 'psr4');
JLoader::registerNamespace('App\\Admin', JPATH_COMPONENT_ADMINISTRATOR, false, false, 'psr4');

I would probably also lean towards keeping shared assets in the site side of things.

  • I'm thinking that namespaces are best too. But, not in a libraries directory? Why would you put it in the site portion?
    – nimble
    Apr 27, 2018 at 21:47
  • You mean the shared assets? I lean towards keeping anything that is going to be accessible by the public on the site side of things, just for consistency.
    – Ben Harold
    Apr 30, 2018 at 15:18

Your Answer

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

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