Reputation: 551
I'm trying to instantiate a controller and execute some methods but no result :(
jimport('joomla.application.component.controller');
$controller = JController::getInstance('com_shop');
$controller->my_method($arg1, $arg2);
Any idea?
Upvotes: 0
Views: 432
Reputation: 585
following is controller instantiation code taken form lender. And you don't need to use jimport in Joomla 3 extensions. Joomla auto load all classes starting with J
prefix.
<?php // No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
//sessions
jimport( 'joomla.session.session' );
//load tables
JTable::addIncludePath(JPATH_COMPONENT.'/tables');
//load classes
JLoader::registerPrefix('Lendr', JPATH_COMPONENT);
//Load plugins
JPluginHelper::importPlugin('lendr');
//application
$app = JFactory::getApplication();
// Require specific controller if requested
if($controller = $app->input->get('controller','default')) {
require_once (JPATH_COMPONENT.'/controllers/'.$controller.'.php');
}
// Create the controller
$classname = 'LendrController'.$controller;
$controller = new $classname();
// Perform the Request task
$controller->execute();
Upvotes: 0
Reputation: 1345
This won't work try: JControllerLegacy::getInstance('CONTROLLERNAME')
assuming that the controller you are calling follows the naming convention
<COMPONENTNAME><Controller><CONTROLLERNAME>
for example WeblinksControllerWeblink
Upvotes: 1