How does Joomla direct the controller method when submitting a form?

In the case where the form action is set to something like:

action="<?php echo JRoute::_('index.php?option=com_test&layout=edit&id='.(int) $this->item->id); ?>"

and the form also contains hidden input:

<input type="hidden" name="task" value="testctrl.save" />

How does Joomla route to the controller method?

I would understand if this task was in a form action, but I don’t see how he selects a task from hidden input in order to route the corresponding method in the controller method testctrl

+3
source share
2 answers

It is not that difficult. Your directory com_mycomhas a file named mycom.php. It has a few lines that look like this:

$controller = JControllerLegacy::getInstance('Contact');
$controller->execute(JFactory::getApplication()->input->get('task'));
$controller->redirect();

See an example here: https://github.com/joomla/joomla-cms/blob/staging/components/com_contact/contact.php#L15

, , . .

:

https://github.com/joomla/joomla-cms/blob/staging/components/com_contact/controller.php#L19

, : " , , ?". , JControllerLegacy:

https://github.com/joomla/joomla-cms/blob/staging/libraries/legacy/controller/legacy.php#L701

public function execute($task)
{ ... }

- , . . , !

+6

controller

<input type="hidden" name="task" value="testctrl.save" />

<input type="hidden" name="controller" value="testctrl" />
<input type="hidden" name="task" value="save" />

, .

, com_test, test.php

Joomla.

jimport('joomla.application.component.controller');

, .

createFileName() getInstance() libraries/joomla/application/component/controller.php

.

Joomla 1.5 Joomla 2.x

Edit

Joomla3.x

Joomla 3. x .

jimport('joomla.application.component.controller'); Joomla 3.x

$controller = JControllerLegacy::getInstance('Content');

JControllerLegacy libraries\legacy\controller\legacy.php

createFileName() ,getInstance() .

, .

+3

All Articles