3

As we can load third party component model like this:

Loader::import('joomla.application.component.model');
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

3
jimport('joomla.application.component.controller');
JLoader::import('controllername', JPATH_ROOT . '/components/com_componentname/controllers');
$controller = JControllerLegacy::getInstance('controllername');
$controller->execute('task');

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

1

Try this:

JLoader::register('Helpername', dirname(__FILE__) . DS . 'helpers' . DS . 'filename');
jimport('joomla.application.component.controller');
JLoader::import('Controllername', JPATH_ROOT . '/components/com_componentname/controllers');
$model = JControllerLegacy::getInstance('controller name');
$model->execute(JFactory::getApplication()->input->get("task"));
2
  • 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
1

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

JLoader::import('joomla.application.component.controller');
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 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.