Nicotine

Open source framework for PHP & MySQL

Downloads Page

Available helpers

They are globaly available, no need to import anything.

d($var, $withType = false); custom var dumper. Script will continue execution. Set to true the second argument on CLI and AJAX request, in order to var_dump, instead of print_r.

dd($var, $withType = false); custom var dumper. Script will stop execution. Set to true the second argument on CLI and AJAX request, in order to var_dump, instead of print_r.

href(string $to = '', array $params = []) Returns an URL path to a resource. Without arguments it returns base URL path to the site side.

<?php
print href('admin/products/list', ['sort_by' => 'id''sort_order' => 'desc']);
// https://example.com/admin/products/list.html?sort_by=id&sort_order=desc

get_roles() get member logged in roles.

has_role(string $role) check if session user has specific role.

is_natural(mixed $var): bool check whether the argument is a true natural number e.g. 1, 2, 3, ...n, and is greater than zero (like a database primary key).

transient(string $key, mixed $default = null) repopulate form field if the validation fails. Example:

<input type="text" name="name" value="<?php print transient('name''Unknown'); ?>" />

email($to, $subject, $body, $headers = []) On PRODUCTION_MODE all emails will be sent to the real address. On STAGING_MODE all emails will be redirected to redirectEmailsTo configuration directive. On DEVELOPMENT_MODE arguments this helper will be printed and no email will be sent. Play with errorReporting configuration directive.

empty_directory(string $directory, string $exclude = '.keep') unlink files from a directory, except $exclude.

__() translate a message. See languages.