I am struggling to understand how to call sub controllers from a joomla component. What are to be placed in the controllers folder?
I have the entry point of my component like -
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// require helper file
JLoader::register('TieraerzteHelper', dirname(__FILE__) . DS . 'helpers' . DS . 'my_helper.php');
// import joomla controller library
jimport('joomla.application.component.controller');
$controller = JController::getInstance('MyController');
// Get the task
$jinput = JFactory::getApplication()->input;
$task = $jinput->get('task', "", 'STR' );
// Perform the Request task
$controller->execute($task);
// Redirect if set by the controller
$controller->redirect();
Then if I want to call a controller, which is placed in the controllers folder, how do I do that?
You do a task=controller.function
As an example: You want to call the MycomponentControllerFoo
in /controllers/foo.php and execute the function bar()
. You use the following URL to call this:
index.php?option=com_mycomponent&task=foo.bar
Or you can use a form where there is a hidden task field.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With