AurumPHP — Application Helpers Reference

Complete documentation of all helpers available in AurumPHP applications
Source files: core/helpers.php & core/event_helpers.php
Auto-load: All helpers are automatically available on every generated page/controller

1. URL & Navigation core/helpers.php

HelperSignatureDescription
base_url()base_url(string $path = ''): stringGenerate URL relative to project root. Automatically appends ?v=filemtime for CSS/JS assets.
redirect()redirect(string $path = ''): voidRedirect to a relative URL. Calls exit immediately after redirect.

2. Database — Legacy Style core/helpers.php

HelperSignatureDescription
CustomQuery()CustomQuery(string $sql, array $params = []): PDOStatementExecute raw SQL with a prepared statement. Returns PDOStatement.
db_fetch_array()db_fetch_array(PDOStatement $stmt): array|falseFetch a single row from a query result. Equivalent to fetch(PDO::FETCH_ASSOC).
db_fetch_all()db_fetch_all(PDOStatement $stmt): arrayFetch all rows. Equivalent to fetchAll(PDO::FETCH_ASSOC).
db_num_rows()db_num_rows(PDOStatement $stmt): intCount rows from a statement. Wraps rowCount().
db_insert_id()db_insert_id(): stringGet the last insert ID after an INSERT.
db_escape()db_escape(string $value): stringEscape a string. Use prepared statements whenever possible.

3. Session & Flash core/helpers.php

HelperSignatureDescription
page_set_var()page_set_var(string $key, mixed $value): voidSet a page-level variable (stored in $_SESSION). Useful for passing data between events/pages.
page_get_var()page_get_var(string $key, mixed $default = null): mixedRetrieve a page-level variable previously set with page_set_var().
flash()flash(string $message, string $type = 'success'): voidSet a flash message displayed once on the next page. Types: success, error, warning.

4. Event Error & State core/helpers.php

HelperSignatureDescription
event_error()event_error(string $message): neverStop execution with an error. AJAX → JSON error response; Normal → $_SESSION['flash_error'].
event_set()event_set(string $key, mixed $value): voidSet an event state variable ($GLOBALS, valid for the current request only).
event_get()event_get(string $key, mixed $default = null): mixedRetrieve an event state variable set with event_set().

5. HTML Injection core/helpers.php

HelperSignatureDescription
add_html_top()add_html_top(string $html): voidInject HTML at the top of the page (before main content).
add_html_bottom()add_html_bottom(string $html): voidInject HTML at the bottom of the page (after main content).

6. Field Control core/helpers.php

HelperSignatureDescription & Suitable Event
set_default_value()set_default_value(string $field, mixed $value): voidSet a default field value in the Add form. Event: Add Page — Before Display
hide_field()hide_field(string ...$fields): voidHide fields from the view. Supports multiple fields. Event: Before Display (Add/Edit/View/List)
show_field()show_field(string ...$fields): voidShow fields that were previously hidden. Event: Before Display
set_readonly_field()set_readonly_field(string ...$fields): voidMake fields read-only (visible but not editable). Event: Edit Page — Before Display

7. Email & Formatting core/helpers.php

HelperSignatureDescription
send_email()send_email(string $to, string $subject, string $body, string $from = ''): boolSend an HTML email. For full features (CC/BCC/attachment) use aurum_mail().
format_currency()format_currency(float $amount, string $symbol = 'Rp', int $decimals = 0): stringFormat a number as currency. Example: format_currency(1500000) → "Rp 1.500.000"
format_date()format_date(string $date, string $format = 'd/m/Y'): stringFormat a date. Returns - if empty/0000-00-00. Example: format_date('2024-01-15') → "15/01/2024"

8. Auth & User core/helpers.php

HelperSignatureDescription
current_user()current_user(): stringGet the username of the logged-in user. Example: 'admin', 'john'
current_group_id()current_group_id(): intGet the group_id of the logged-in user. Admin = 1, Manager = 2, etc.
is_admin()is_admin(): boolCheck if the current user is admin (group_id === 1). Same as current_group_id() === 1.

9. Utility core/helpers.php

HelperSignatureDescription
auto_number()auto_number(string $prefix, string $table, string $field, int $pad = 5): stringGenerate an auto-increment number. Example: auto_number('INV-', 'sales', 'invoice_no') → "INV-00001"
value_exists()value_exists(string $table, string $field, mixed $value, int $excludeId = 0): boolCheck for duplicate values in a table. $excludeId is useful on edit to exclude the current record.

10. Event Database Connection core/event_helpers.php

HelperSignatureDescription
evt_db()evt_db(?PDO $pdo = null): PDOGet/inject a PDO instance. If null, automatically creates a connection from config.
SetConnection()SetConnection(?PDO $pdo = null): PDOSet/get the active connection. Similar to evt_db() but can be overridden per-request.

11. Event Query Execution core/event_helpers.php

HelperSignatureDescription
PrepareSQL()PrepareSQL(string $sql, array $params = []): arrayWrap SQL + params into an array. For passing to Exec() or Query().
Exec()Exec(string|array $sql, array $params = []): int|falseExecute a query, returns rowCount. On error → LastError().
Query()Query(string|array $sql, array $params = []): PDOStatement|falseExecute a query, returns PDOStatement. On error → returns false.
LastId()LastId(): string|falseGet the last insert ID after Exec() or Query().
LastError()LastError(): stringGet the last error message from Exec() or Query().

12. Event Data Retrieval core/event_helpers.php

HelperSignatureDescription
DBLookup()DBLookup(string|array $sql, array $params = []): mixedGet a single value (first column, first row). Returns null if not found.
DBLookupRow()DBLookupRow(string|array $sql, array $params = []): array|nullGet a single full row. Returns null if not found.
DBQueryRows()DBQueryRows(string|array $sql, array $params = []): array|falseGet all rows. Returns false on error.

13. Event Utility core/event_helpers.php

HelperSignatureDescription
evt_identifier()evt_identifier(string $name): stringSanitize a database identifier (backtick wrapper). Throws an exception if the name is invalid.
evt_value()evt_value(array $values, string $field, mixed $default = null): mixedGet a value from the $values array with a default. Safe for checking key existence.

14. Event Helpers — evt_* Series core/event_helpers.php

The evt_* helpers for concise and safe CRUD operations. All use prepared statements automatically.

HelperSignatureDescription
evt_number()evt_number(array $values, string $field, float $default = 0): floatGet a field value as a number. Ideal for currency inputs (e.g. "Rp 1,500,000" → 1500000).
evt_set_value()evt_set_value(array &$values, string $field, mixed $value): voidModify a field value before saving. Used in Process Record Values.
evt_now()evt_now(string $format = 'Y-m-d H:i:s'): stringGet the current datetime. Example: evt_now('Y-m-d') → "2024-01-15"
evt_insert()evt_insert(?PDO $pdo, string $table, array $data): stringInsert a record into another table. Returns last insert ID. $pdo can be null.
evt_update()evt_update(?PDO $pdo, string $table, array $data, array $where): intUpdate records by condition. $where is required (cannot be empty).
evt_delete()evt_delete(?PDO $pdo, string $table, array $where): intDelete records by condition. $where is required (cannot be empty).
evt_first()evt_first(?PDO $pdo, string $table, array $where = [], array $columns = ['*']): ?arrayGet a single record. Returns null if not found.
evt_all()evt_all(?PDO $pdo, string $table, array $where = [], array $columns = ['*'], string $orderBy = '', int $limit = 0): arrayGet multiple records. Supports filters, column selection, ordering, and limit.
evt_sum()evt_sum(?PDO $pdo, string $table, string $field, array $where = []): floatSum a field's values. Example: total sales per employee.
evt_count()evt_count(?PDO $pdo, string $table, array $where = []): intCount records matching the given conditions.
evt_raw()evt_raw(string $sql, array $params = []): arraySafe SQL expression for evt_insert()/evt_update(). Example: evt_raw('qty - ?', [1])
evt_only()evt_only(array $values, array $fields): arrayPick only specific fields from $values.
evt_except()evt_except(array $values, array $fields): arrayRemove specific fields from $values.

Quick Reference — All Helpers Summary

CategoryHelperSource File
URL & Navigationbase_url() redirect()core/helpers.php
Database LegacyCustomQuery() db_fetch_array() db_fetch_all() db_num_rows() db_insert_id() db_escape()core/helpers.php
Session & Flashpage_set_var() page_get_var() flash()core/helpers.php
Event Error & Stateevent_error() event_set() event_get()core/helpers.php
HTML Injectionadd_html_top() add_html_bottom()core/helpers.php
Field Controlset_default_value() hide_field() show_field() set_readonly_field()core/helpers.php
Email & Formattingsend_email() format_currency() format_date()core/helpers.php
Auth & Usercurrent_user() current_group_id() is_admin()core/helpers.php
Utilityauto_number() value_exists()core/helpers.php
Event DB Connectionevt_db() SetConnection()core/event_helpers.php
Event QueryPrepareSQL() Exec() Query() LastId() LastError()core/event_helpers.php
Event LookupDBLookup() DBLookupRow() DBQueryRows()core/event_helpers.php
Event Utilityevt_identifier() evt_value()core/event_helpers.php
Event CRUD (evt_*)evt_number() evt_set_value() evt_now() evt_insert() evt_update() evt_delete() evt_first() evt_all() evt_sum() evt_count() evt_raw() evt_only() evt_except()core/event_helpers.php

Popular Usage Examples

Calculate total before save

EventCode
Add Page — Process Record Values$h = evt_number($values, 'price'); $d = evt_number($values, 'discount'); evt_set_value($values, 'total', $h - ($h * $d / 100));

Validate before save

EventCode
Add Page — Before Record Addedif (evt_number($values, 'price') <= 0) event_error('Price must be > 0');
Edit Page — Before Record Updatedif (value_exists('employees', 'email', $values['email'], (int)$keys['id'])) event_error('Email already in use');

Insert log / update another table after save

EventCode
Add Page — After Record Addedevt_insert($pdo ?? null, 'log', ['record_id' => $id, 'action' => 'add', 'created_at' => evt_now()]);
Add Page — After Record Addedevt_update($pdo ?? null, 'stock', ['qty' => evt_raw('qty - ?', [$qty])], ['id' => $itemId]);

Hide/readonly fields based on user role

EventCode
Edit Page — Before Displayif (!is_admin()) { set_readonly_field('price', 'discount'); hide_field('margin'); }
View Page — Before Displayif (current_group_id() !== 1) hide_field('salary', 'contract_value');

Auto-number invoice

EventCode
Add Page — Process Record Valuesevt_set_value($values, 'invoice_no', auto_number('INV-', 'sales', 'invoice_no'));