go back

How do I call a Joomla Controller from another Controller?

Answer

Joomla MVC is a great way to seggregate your code into different functional units. Controllers have access to all their own resources but if you want to sidechain a controller to another controller there isn't really any function within the controller to call another controller. The best way call another controller is this way:

include_once(JPATH_COMPONENT . DS . 'controllers' . DS 
.'ControllerName' . '.php');

$controller = new ControllerName();
$controller->execute('task');

Include the controller just like you did in the main component, and then create a new one in memory, execute your task.

Hope this helps save someone time.

Category

Joomla Programming

Tags for this item

programming

messages