Joomla controllers, how do they work?

I'm struggling to figure out how to call helper controllers from the joomla component. What needs to be placed in the controller folder?

I have an entry point for my component, for example -

<?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 the controller, which is placed in the controllers folder, how to do it?

+4
source share
1 answer

You do task=controller.function

As an example: you want to call MycomponentControllerFoo in /controllers/foo.php and execute the bar() function. To do this, you use the following URL:

 index.php?option=com_mycomponent&task=foo.bar 

Or you can use a form that has a hidden task field.

+7
source

All Articles