Controller
extends Controller
in component
uses
TraitSession, TraitController
Replaces the standard OpenCart Controller class with extended functionality. Recommended as a base class for all controllers of Ka extensions.
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.
- 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.
- 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() : bool
- Hook called at the end of the constructor. Override it in child classes to run initialization code.
- 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.
Properties
$children
protected
mixed
$children
= array()
$data
protected
mixed
$data
= array()
$is_render_disabled
protected
mixed
$is_render_disabled
= false
$kadb
protected
mixed
$kadb
= null
$lastError
protected
mixed
$lastError
$template
protected
mixed
$template
= ''
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.
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
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()
Hook called at the end of the constructor. Override it in child classes to run initialization code.
protected
onLoad() : bool
Return values
bool —Always true.
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()