Cake\Controller\Controller::__construct PHP Method

__construct() public method

Sets a number of properties based on conventions if they are empty. To override the conventions CakePHP uses you can define properties in your class declaration.
public __construct ( Cake\Network\Request $request = null, Response $response = null, string | null $name = null, Cake\Event\EventManager | null $eventManager = null, Cake\Controller\ComponentRegistry | null $components = null )
$request Cake\Network\Request Request object for this controller. Can be null for testing, but expect that features that use the request parameters will not work.
$response Cake\Network\Response Response object for this controller.
$name string | null Override the name useful in testing when using mocks.
$eventManager Cake\Event\EventManager | null The event manager. Defaults to a new instance.
$components Cake\Controller\ComponentRegistry | null The component registry. Defaults to a new instance.
    public function __construct(Request $request = null, Response $response = null, $name = null, $eventManager = null, $components = null)
    {
        if ($name !== null) {
            $this->name = $name;
        }
        if ($this->name === null && isset($request->params['controller'])) {
            $this->name = $request->params['controller'];
        }
        if ($this->name === null) {
            list(, $name) = namespaceSplit(get_class($this));
            $this->name = substr($name, 0, -10);
        }
        $this->setRequest($request !== null ? $request : new Request());
        $this->response = $response !== null ? $response : new Response();
        if ($eventManager !== null) {
            $this->eventManager($eventManager);
        }
        $this->modelFactory('Table', [$this->tableLocator(), 'get']);
        $modelClass = ($this->plugin ? $this->plugin . '.' : '') . $this->name;
        $this->_setModelClass($modelClass);
        if ($components !== null) {
            $this->components($components);
        }
        $this->initialize();
        $this->_mergeControllerVars();
        $this->_loadComponents();
        $this->eventManager()->on($this);
    }

Usage Example

 public function __construct($request = null, $response = null)
 {
     $request->webroot = '/';
     Router::setRequestInfo($request);
     parent::__construct($request, $response);
 }
All Usage Examples Of Cake\Controller\Controller::__construct