KMP PHP API Reference

KmpHelper extends Helper
in package

KMP View Helper providing custom UI components and template utilities.

Features: auto-complete controls, block management, data conversion (CSV), boolean display, application settings access, and navigation cell rendering. Available in templates as $this->Kmp->methodName().

Tags
see
StaticHelpers

For core utility functions

AppView

For view integration

Table of Contents

Properties

$helpers  : array<string|int, string>
Helpers used by KMP helper methods.
$currentOpenBlock  : string
Tracks the currently open block name.
$mainView  : AppView|null
Main view reference for block management across view cells.

Methods

appNav()  : string
Render application navigation using cell.
assetUrl()  : string
Resolve an app-setting asset value to a browser URL.
autoCompleteControl()  : string
Render auto complete control using element.
beforeRender()  : void
Run before view rendering.
bool()  : string
Returns a boolean icon for visual representation of true/false values.
comboBoxControl()  : string
Render a combo box control with predefined options.
endBlock()  : void
End the currently open view block.
getAppSetting()  : mixed
Get application setting from the database configuration.
getAppSettingsStartWith()  : array<string|int, mixed>
Get application settings that start with a specific key prefix.
getUploadLimits()  : array<string|int, mixed>
Get PHP upload configuration limits in bytes.
makeCsv()  : string
Convert array data to CSV format for download/export.
makePossessive()  : string
Return the possessive form of a name.
startBlock()  : string
Start a named view block for content organization.
workflowStatusBadge()  : string
Render a Bootstrap status badge for workflow statuses.
formatBytes()  : string
Format bytes to human-readable string
parsePhpSize()  : int
Parse PHP size notation to bytes

Properties

$helpers

Helpers used by KMP helper methods.

protected array<string|int, string> $helpers = ['Url']

$currentOpenBlock

Tracks the currently open block name.

private static string $currentOpenBlock = ''

$mainView

Main view reference for block management across view cells.

private static AppView|null $mainView = null

Methods

appNav()

Render application navigation using cell.

public appNav(array<string|int, mixed> $appNav, Member $user[, array<string|int, mixed> $navBarState = [] ]) : string

Delegates to AppNavCell for main navigation rendering.

Parameters
$appNav : array<string|int, mixed>

Navigation configuration array

$user : Member

Current authenticated user

$navBarState : array<string|int, mixed> = []

Current navigation state

Return values
string

Rendered navigation HTML

assetUrl()

Resolve an app-setting asset value to a browser URL.

public assetUrl(string|null $asset) : string

Supports new public asset URLs and legacy webroot/img filenames.

Parameters
$asset : string|null

App setting asset value

Return values
string

autoCompleteControl()

Render auto complete control using element.

public autoCompleteControl(mixed $Form, string $inputField, string $resultField, string $url[, string|null $label = null ][, bool $required = false ][, bool $allowOtherValues = false ][, int $minLength = 1 ][, array<string|int, mixed> $additionalAttrs = [] ]) : string

Creates an autocomplete input that loads suggestions from a URL endpoint. Uses Stimulus.js autocomplete controller for JavaScript functionality.

Parameters
$Form : mixed

The CakePHP Form helper instance

$inputField : string

Name of the display input field

$resultField : string

Name of the hidden field for selected value

$url : string

URL endpoint providing autocomplete suggestions (JSON)

$label : string|null = null

Label text for the control

$required : bool = false

Whether the field is required

$allowOtherValues : bool = false

Whether to allow custom values

$minLength : int = 1

Minimum characters before triggering autocomplete

$additionalAttrs : array<string|int, mixed> = []

Additional HTML attributes

Return values
string

Rendered autocomplete control HTML

beforeRender()

Run before view rendering.

public beforeRender(Event $event) : void
Parameters
$event : Event

bool()

Returns a boolean icon for visual representation of true/false values.

public bool(bool $value, HtmlHelper $Html[, array<string|int, mixed> $options = [] ]) : string

Uses Bootstrap icons: green check-circle-fill for true, red x-circle for false.

Parameters
$value : bool

The boolean value to represent

$Html : HtmlHelper

CakePHP HTML helper instance

$options : array<string|int, mixed> = []

Additional HTML attributes for the icon

Return values
string

HTML string containing the Bootstrap icon

comboBoxControl()

Render a combo box control with predefined options.

public comboBoxControl(mixed $Form, string $inputField, string $resultField, array<string|int, mixed> $data[, string|null $label = null ][, bool $required = false ][, bool $allowOtherValues = false ][, array<string|int, mixed> $additionalAttrs = [] ]) : string

Creates a dropdown with optional custom value entry.

Parameters
$Form : mixed

The CakePHP Form helper instance

$inputField : string

Name of the display input field

$resultField : string

Name of the hidden field for selected value

$data : array<string|int, mixed>

Options array [value => label]

$label : string|null = null

Label text for the control

$required : bool = false

Whether the field is required

$allowOtherValues : bool = false

Whether to allow custom values

$additionalAttrs : array<string|int, mixed> = []

Additional HTML attributes

Return values
string

Rendered combo box HTML

endBlock()

End the currently open view block.

public endBlock() : void

getAppSetting()

Get application setting from the database configuration.

public getAppSetting(string $key[, string|null $fallback = null ]) : mixed
Parameters
$key : string

The setting key to retrieve

$fallback : string|null = null

Default value if setting not found

Return values
mixed

The setting value or fallback

getAppSettingsStartWith()

Get application settings that start with a specific key prefix.

public getAppSettingsStartWith(string $key) : array<string|int, mixed>
Parameters
$key : string

The prefix to search for in setting keys

Return values
array<string|int, mixed>

Array of settings where keys start with the prefix

getUploadLimits()

Get PHP upload configuration limits in bytes.

public getUploadLimits() : array<string|int, mixed>

Returns the smaller of upload_max_filesize and post_max_size.

Return values
array<string|int, mixed>

Array with 'maxFileSize' in bytes and 'formatted' human-readable string

makeCsv()

Convert array data to CSV format for download/export.

public makeCsv(array<string|int, mixed> $data) : string

Delegates to StaticHelpers for consistent CSV formatting across the application. Useful for generating CSV exports from view data.

Parameters
$data : array<string|int, mixed>

Array of data to convert to CSV

Tags
see
StaticHelpers::arrayToCsv()

For implementation details

example
$csvData = $this->Kmp->makeCsv([
    ['Name', 'Email', 'Branch'],
    ['John Doe', 'john@example.com', 'East Kingdom'],
    ['Jane Smith', 'jane@example.com', 'Middle Kingdom']
]);
Return values
string

CSV formatted string

makePossessive()

Return the possessive form of a name.

public makePossessive(string $name) : string

Trims input and appends an apostrophe or apostrophe-s depending on whether the name ends with an "s" (case-insensitive).

Parameters
$name : string

Name to convert

Return values
string

Possessive form (empty string for blank input)

startBlock()

Start a named view block for content organization.

public startBlock(string $block) : string
Parameters
$block : string

Name of the block to start

Return values
string

Current content of the block (if any)

workflowStatusBadge()

Render a Bootstrap status badge for workflow statuses.

public workflowStatusBadge(string $status) : string
Parameters
$status : string

Status string (e.g., 'running', 'approved', 'draft')

Return values
string

HTML badge markup

formatBytes()

Format bytes to human-readable string

private formatBytes(int $bytes[, int $precision = 0 ]) : string
Parameters
$bytes : int

Size in bytes

$precision : int = 0

Decimal precision

Return values
string

Formatted size string (e.g., '25MB', '1.5GB')

parsePhpSize()

Parse PHP size notation to bytes

private parsePhpSize(string $size) : int

Converts PHP ini size notation (e.g., '25M', '2G', '512K') to bytes. Handles various formats used in php.ini configuration.

Parameters
$size : string

Size string from PHP ini setting

Return values
int

Size in bytes

On this page

Search results