As we can load third party component model like this:

JLoader::import('modelname', JPATH_ROOT.'/components/com_componentname/models');
$model = JModelLegacy::getInstance( 'modelname', 'ComponentNameModel' );

Is there any similar way to load sub-controller of a third party component and execute a method in it?

3 Answers 3

JLoader::import('controllername', JPATH_ROOT . '/components/com_componentname/controllers');
$controller = JControllerLegacy::getInstance('controllername');

Not sure what you want to do, which task you want to execute, etc. But that should work as a start.


Try this:

JLoader::register('Helpername', dirname(__FILE__) . DS . 'helpers' . DS . 'filename');
JLoader::import('Controllername', JPATH_ROOT . '/components/com_componentname/controllers');
$model = JControllerLegacy::getInstance('controller name');
  • This is what I mentioned in my question, I can load model with your code from /components/com_componentname/models. But I am looking something to load controller, not the model. I believe its a typo in your code or you have not understood my question. Let me know.
    – Nagarjun
    Jun 17, 2015 at 12:26
  • Sorry, This is my mistake JLoader::import('Controllername', JPATH_ROOT . '/components/com_componentname/controllers');
    – Jextn
    Jun 17, 2015 at 12:28

I could be wrong and haven't tested this, but try using:

JLoader::import('modelname', JPATH_ROOT . '/components/com_componentname/controllers');
$controller = JControllerLegacy::getInstance('controllername');

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.