Controller class abstract

Framework\MVC\Controller

Class Controller.

Extends Framework\Routing\RouteActions

Defined in libraries/mvc/src/Controller.php

Properties #

$request
The matched route Request.
$response
The matched route Response.
$loadModels
Set true to load models in properties.

$request

protected \Framework\HTTP\Request $request

The matched route Request.

$response

protected \Framework\HTTP\Response $response

The matched route Response.

$loadModels

protected bool $loadModels = true

Set true to load models in properties.

Methods #

__construct()
Controller constructor.
prepareModels()
Initialize models in properties.
render()
Render a view.
validate()
Validate data.

__construct()

public function __construct(\Framework\HTTP\Request $request, \Framework\HTTP\Response $response)

Controller constructor.

Parameters
  • \Framework\HTTP\Request $request
  • \Framework\HTTP\Response $response

prepareModels()

protected function prepareModels(): static

Initialize models in properties.

Returns static

render()

protected function render(string $view, array $variables = array ( ), string $instance = 'default'): string

Render a view.

Parameters
  • string $view - The view file
  • array $variables - The variables passed to the view
  • string $instance - The View service instance name
Returns string - The rendered view contents

validate()

protected function validate(array $data, array $rules, array $labels = array ( ), array $messages = array ( ), string $instance = 'default'): array

Validate data.

Parameters
  • array $data - The data to be validated
  • array $rules - An associative array with field as keys and values as rules
  • array $labels - An associative array with fields as keys and label as values
  • array $messages - A multi-dimensional array with field names as keys and values as arrays where the keys are rule names and values are the custom error message strings
  • string $instance - The Validation service instance name
Returns array - An empty array if validation pass or an associative array with field names as keys and error messages as values

Inherited methods #