Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

joomla controllers how they work?

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?

like image 698
fefe Avatar asked Mar 31 '13 15:03

fefe


1 Answers

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.

like image 106
Bakual Avatar answered Sep 25 '22 17:09

Bakual