Ka Extensions for OpenCart 4

This documentation applies to Ka Extensions for OpenCart 4.x only. It is not compatible with OpenCart 3.

ControllerForm extends Controller
in component
uses TraitControllerForm

AbstractYes

A base controller class for a basic form page. It builds the field list, url parameters and breadcrumbs, validates submitted values and passes pagination data to the template.

Table of Contents

Properties

Methods

__construct()  : mixed
Creates the controller, initializes the Ka database wrapper, adds the Ka Extensions stylesheet in the admin area and calls onLoad().
getLastError()  : mixed
Returns the last error.
addBreadcrumb()  : void
Adds a breadcrumb to the page data.
addTopMessage()  : mixed
Adds a message shown at the top of the page; stored in the session.
disableRender()  : mixed
Disables rendering so child classes can change data or the template before output. Unifies the interface with KaController.
enableRender()  : mixed
Enables rendering again. Unifies the interface with KaController.
getFields()  : array<string|int, mixed>
Returns the form fields definition. Each field is an array with keys like 'code', 'type',
'title', 'required'. Missing 'code' values are filled in with the array keys.
getFieldsWithData()  : array<string|int, mixed>
Fills fields with values from old and new data and attaches errors.
getFieldValues()  : array<string|int, mixed>
Returns code => value pairs from fields.
getFieldWithData()  : array<string|int, mixed>
Fills a field with its value: from new data, then old data, then the default value. Formats prices and prepares thumbnails for image fields.
getPageUrlParams()  : array<string|int, mixed>
Returns page url parameters with their default values. They are passed to UrlParams.
getRenderData()  : array<string|int, mixed>
Returns the template data merged with the temporary view data from the loader.
getRenderTemplate()  : string
Returns the temporary view route from the loader.
getSession()  : mixed
Returns a reference to a value in the session area of the current class; null is created if missing.
getTopMessages()  : array<string|int, mixed>|null
Returns top page messages from the session.
loadAdminPageBlocks()  : mixed
Loads admin page blocks (header, left column, footer) and user_token into the data.
loadCustomerPageBlocks()  : mixed
Loads storefront page blocks (header, footer, columns, content top and bottom) into the data.
onLoad()  : void
Loads common language strings, prepares the form fields, adds the 'Home' breadcrumb and
initializes url parameters of the page.
render()  : string
Renders the template with data and page blocks (children or the standard header, footer and columns). Returns an empty string when rendering is disabled. Example:
setSession()  : mixed
Stores a value in the session area of the current class.
showPage()  : mixed
Renders the page. Adds pagination data if the pagination object is set and enables a multipart
form when the fields contain a file field.
validate()  : bool
Validates the modify permission and the posted field values.
validateField()  : bool
Validates a field (required, presence, number min and max) and writes errors to $this->errors.
validateFields()  : bool
Validates all fields.
validateModify()  : bool
Checks that the current user has the 'modify' permission for the current route. Adds an error
message to the top messages otherwise.

Properties

Methods

__construct()

Creates the controller, initializes the Ka database wrapper, adds the Ka Extensions stylesheet in the admin area and calls onLoad().

public __construct(mixed $registry) : mixed

$registry — OpenCart registry.

Parameters
$registry : mixed

getLastError()

Returns the last error.

public getLastError() : mixed
Return values
mixed —

Last error.

addBreadcrumb()

Adds a breadcrumb to the page data.

protected addBreadcrumb(mixed $text[, mixed $href = '' ]) : void

$text — breadcrumb text. $href — breadcrumb link.

Parameters
$text : mixed
$href : mixed = ''

addTopMessage()

Adds a message shown at the top of the page; stored in the session.

protected addTopMessage(mixed $msg[, mixed $type = 'S' ]) : mixed

$msg — message text or array of texts. $type — message type, 'S' by default.

Parameters
$msg : mixed
$type : mixed = 'S'

disableRender()

Disables rendering so child classes can change data or the template before output. Unifies the interface with KaController.

protected disableRender() : mixed

enableRender()

Enables rendering again. Unifies the interface with KaController.

protected enableRender() : mixed

getFields()

Returns the form fields definition. Each field is an array with keys like 'code', 'type', 'title', 'required'. Missing 'code' values are filled in with the array keys.

protected abstract getFields() : array<string|int, mixed>
Return values
array<string|int, mixed>

getFieldsWithData()

Fills fields with values from old and new data and attaches errors.

protected getFieldsWithData(mixed $fields, mixed $old_data[, mixed $new_data = null ][, mixed $errors = array() ]) : array<string|int, mixed>

$fields — field metadata arrays. $old_data — old data, e.g. from the database. $new_data — new data when the form was submitted, otherwise null. $errors — errors indexed by field code.

Parameters
$fields : mixed
$old_data : mixed
$new_data : mixed = null
$errors : mixed = array()
Return values
array<string|int, mixed> —

Fields with values.

getFieldValues()

Returns code => value pairs from fields.

protected getFieldValues(mixed $fields) : array<string|int, mixed>

$fields — fields with values.

Parameters
$fields : mixed
Return values
array<string|int, mixed> —

Field values.

getFieldWithData()

Fills a field with its value: from new data, then old data, then the default value. Formats prices and prepares thumbnails for image fields.

protected getFieldWithData(mixed $k, mixed $f, mixed $old_data, mixed $new_data) : array<string|int, mixed>

$k — field code. $f — field metadata array. $old_data — old data, e.g. from the database. $new_data — new data (POST array) or null.

Parameters
$k : mixed
$f : mixed
$old_data : mixed
$new_data : mixed
Return values
array<string|int, mixed> —

Field with the value.

getPageUrlParams()

Returns page url parameters with their default values. They are passed to UrlParams.

protected abstract getPageUrlParams() : array<string|int, mixed>
Return values
array<string|int, mixed>

getRenderData()

Returns the template data merged with the temporary view data from the loader.

protected getRenderData() : array<string|int, mixed>
Return values
array<string|int, mixed> —

Template data.

getRenderTemplate()

Returns the temporary view route from the loader.

protected getRenderTemplate() : string
Return values
string —

Template route.

getSession()

Returns a reference to a value in the session area of the current class; null is created if missing.

protected & getSession(mixed $key) : mixed

$key — value key.

Parameters
$key : mixed
Return values
mixed —

Reference to the value.

getTopMessages()

Returns top page messages from the session.

protected getTopMessages([mixed $clear = true ]) : array<string|int, mixed>|null

$clear — remove messages from the session.

Parameters
$clear : mixed = true
Return values
array<string|int, mixed>|null —

Messages or null.

loadAdminPageBlocks()

Loads admin page blocks (header, left column, footer) and user_token into the data.

protected loadAdminPageBlocks() : mixed

loadCustomerPageBlocks()

Loads storefront page blocks (header, footer, columns, content top and bottom) into the data.

protected loadCustomerPageBlocks() : mixed

onLoad()

Loads common language strings, prepares the form fields, adds the 'Home' breadcrumb and initializes url parameters of the page.

protected onLoad() : void

render()

Renders the template with data and page blocks (children or the standard header, footer and columns). Returns an empty string when rendering is disabled. Example:

protected render([mixed $tpl = '' ][, mixed $data = array() ]) : string

public function index() { $this->disableRender(); parent::index(); $this->enableRender(); $this->response->setOutput($this->render()); }

$tpl — template name. $data — template variables merged with existing data.

Parameters
$tpl : mixed = ''
$data : mixed = array()
Return values
string —

Rendered page.

setSession()

Stores a value in the session area of the current class.

protected setSession(mixed $key, mixed $value) : mixed

$key — value key. $value — value.

Parameters
$key : mixed
$value : mixed

showPage()

Renders the page. Adds pagination data if the pagination object is set and enables a multipart form when the fields contain a file field.

protected showPage([mixed $page = '' ][, mixed $data = array() ]) : mixed

$page — template route. $data — extra template data.

Parameters
$page : mixed = ''
$data : mixed = array()
Return values
mixed —

Result of Controller::showPage().

validate()

Validates the modify permission and the posted field values.

protected validate() : bool
Return values
bool —

True if the form data are valid.

validateField()

Validates a field (required, presence, number min and max) and writes errors to $this->errors.

protected validateField(mixed $code, mixed $field, mixed $post) : bool

$code — field code. $field — field metadata. $post — submitted data.

Parameters
$code : mixed
$field : mixed
$post : mixed
Return values
bool —

False if the field is required but empty or missing. Min and max errors are recorded but still return true.

validateFields()

Validates all fields.

protected validateFields(mixed $fields, mixed $post) : bool

$fields — field metadata arrays. $post — submitted data.

Parameters
$fields : mixed
$post : mixed
Return values
bool —

True if there are no errors.

validateModify()

Checks that the current user has the 'modify' permission for the current route. Adds an error message to the top messages otherwise.

protected validateModify() : bool
Return values
bool —

True if the permission is granted.


        
On this page

Search results