Joomla Display Controller
The display controller is the main controller file for the component. As the component grows in complexity, a page's controller handles model fetching, form submissions, and so on.
The MVC concept is similar for back-end admin part and front-end site part.
Admin
Here, it simply sets its default view and leaves the rest to its parent controller (BaseController)
File Location: admin/src/Controller/DisplayController.php
namespace JohnSmith\Component\HelloWorld\Administrator\Controller;
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Controller\BaseController;
class DisplayController extends BaseController
{
protected $default_view = 'hello';
public function display($cachable = false, $urlparams = array())
{
return parent::display($cachable, $urlparams);
}
}
Site
It contains some basic code to fetch and render a view. However, most of the work is delegated to the parent Joomla! class.
File Location: site/src/Controller/DisplayController.php
namespace JohnSmith\Component\HelloWorld\Site\Controller;
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\Factory;
class DisplayController extends BaseController
{
public function display($cachable = false, $urlparams = array())
{
$document = Factory::getDocument();
$viewName = $this->input->getCmd('view', 'login');
$viewFormat = $document->getType();
$view = $this->getView($viewName, $viewFormat);
$view->document = $document;
$view->display();
}
}