Back to MVCFactory class

Method createController

public \Joomla\CMS\MVC\Controller\ControllerInterface
createController
(mixed $name, mixed $prefix, array $config, \Joomla\CMS\Application\CMSApplicationInterface $app, \Joomla\Input\Input $input)
Method to load and return a controller object.
Parameters
  • string $name The name of the controller
  • string $prefix The controller prefix
  • array $config The configuration array for the controller
  • \Joomla\CMS\Application\CMSApplicationInterface $app The app
  • \Joomla\Input\Input $input The input
Returns
  • \Joomla\CMS\MVC\Controller\ControllerInterface
Since
  • 3.10.0
-
  • \Exception
Class: MVCFactory
Project: Joomla

Method createController - Source code

/**
 * Method to load and return a controller object.
 *
 * @param   string                   $name    The name of the controller
 * @param   string                   $prefix  The controller prefix
 * @param   array                    $config  The configuration array for the controller
 * @param   CMSApplicationInterface  $app     The app
 * @param   Input                    $input   The input
 *
 * @return  \Joomla\CMS\MVC\Controller\ControllerInterface
 *
 * @since   3.10.0
 * @throws  \Exception
 */
public function createController($name, $prefix, array $config, CMSApplicationInterface $app, Input $input)
{
    // Clean the parameters
    $name = preg_replace('/[^A-Z0-9_]/i', '', $name);
    $prefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix);
    $className = $this->getClassName('Controller\\' . ucfirst($name) . 'Controller', $prefix);
    if (!$className) {
        return null;
    }
    $controller = new $className($config, $this, $app, $input);
    $this->setFormFactoryOnObject($controller);
    $this->setDispatcherOnObject($controller);
    return $controller;
}