Ka Extensions for OpenCart 4

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

ControllerSettings extends ControllerInstaller
in component
uses TraitControllerForm

AbstractYes

A base class for a module settings page. It incapsulates all required fields and methods: shows the settings form, validates and saves settings, sets default values on installation and deletes settings on uninstallation.

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().
getDocsLink()  : string
Returns the documentation link from the manifest.
getExtLink()  : string
Returns the extension link from the manifest.
getLastError()  : mixed
Returns the last error.
getTitle()  : string
Returns the extension title with its version, e.g. 'My Module (ver.1.0.0.0)'.
getVersion()  : string
Returns the extension version from the manifest.
index()  : void
Shows the settings page with current setting values.
install()  : bool
Installs the extension, grants permissions to the settings page and saves default setting values.
save()  : bool
Saves posted settings (AJAX). Outputs a JSON response with 'success' or 'error' keys.
uninstall()  : bool
Deletes the extension settings and uninstalls the extension.
addTopMessage()  : mixed
Adds a message shown at the top of the page; stored in the session.
checkCompatibility()  : bool
Checks that the extension is compatible with the installed Ka Extensions library and the database.
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.
getExtensionPages()  : array<string|int, mixed>
Returns a list of extension routes which should get access and modify permissions on extension
installation. The routes are relative to 'extension/<ext_code>/'.
getFields()  : array<string|int, mixed>
Returns the settings fields definition. Field codes are setting keys, 'default_value' is
saved on installation.
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.
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 language files of the library and the extension and prepares the settings fields.
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 and sets it as the response output. Sets heading_title and page_id when missing and adds Ka Extensions CSS and JS.
validate()  : bool
Validates posted setting values.
validateField()  : bool
Validates a field (required, presence, number min and max) and writes errors to $this->errors.
validateFields()  : bool
Validates all fields.

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

Returns the documentation link from the manifest.

public getDocsLink() : string
Return values
string

Returns the extension link from the manifest.

public getExtLink() : string
Return values
string

getLastError()

Returns the last error.

public getLastError() : mixed
Return values
mixed —

Last error.

getTitle()

Returns the extension title with its version, e.g. 'My Module (ver.1.0.0.0)'.

public getTitle() : string
Return values
string

getVersion()

Returns the extension version from the manifest.

public getVersion() : string
Return values
string

install()

Installs the extension, grants permissions to the settings page and saves default setting values.

public install(mixed $params) : bool

$params — see ControllerInstaller::install().

Parameters
$params : mixed
Return values
bool —

True on success.

save()

Saves posted settings (AJAX). Outputs a JSON response with 'success' or 'error' keys.

public save() : bool
Return values
bool —

True if the settings were saved.

uninstall()

Deletes the extension settings and uninstalls the extension.

public uninstall(mixed $params) : bool

$params — see ControllerInstaller::uninstall().

Parameters
$params : mixed
Tags
throws
Exception

If $params is null.

Return values
bool

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'

checkCompatibility()

Checks that the extension is compatible with the installed Ka Extensions library and the database.

protected checkCompatibility(mixed &$tables, mixed &$messages) : bool

$tables — tables definition to check. $messages — receives error messages.

Parameters
$tables : mixed
$messages : mixed
Return values
bool —

True if the extension is compatible.

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

getExtensionPages()

Returns a list of extension routes which should get access and modify permissions on extension installation. The routes are relative to 'extension/<ext_code>/'.

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

getFields()

Returns the settings fields definition. Field codes are setting keys, 'default_value' is saved on installation.

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.

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 language files of the library and the extension and prepares the settings fields.

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 and sets it as the response output. Sets heading_title and page_id when missing and adds Ka Extensions CSS and JS.

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

$template — template name inside the module directory. $data — template variables; replace existing data.

Parameters
$template : mixed = ''
$data : mixed = array()

validate()

Validates posted setting values.

protected validate() : bool
Return values
bool —

True if the values 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.


        
On this page

Search results