Skip to main content
Version: 4.x

Application Helpers

Introduction​

Helpers are shortcut functions loaded into the application that let you quickly perform certain actions. Here is the list of helpers that exist in the BowPHP application. Below are the helpers available in the application.

HTTP management helper​

app, config, response, request, json, download, set_status_code, view, session, cookie, create_csrf_token, csrf_token, csrf_field, method_field, generate_token_csrf, verify_csrf, csrf_time_is_expired, sanitize, secure, set_header, get_header, redirect, send, curl, url, flash, validator, route, old, client_locale, redirect_back

Database​

db, table, get_last_insert_id, db_select, db_select_one, db_insert, db_delete, db_update, db_statement, db_transaction, db_transaction_started, db_rollback, pdo, set_pdo, db_commit, db_seed

Security​

encrypt, decrypt, app_hash, bow_hash

Event management​

listen_event, listen_event_once, listen_transmisson_event, listen_transmisson_event, emitter, emit_event

Storage system​

ftp, s3, config, mount, file_system, cache

Application helper​

app_env, app_assets, app_abort, app_abort_if, app_mode, auth, logger

Strings​

str_slug, str_is_mail, str_is_domain, str_is_slug, str_is_alpha, str_is_lower, str_is_upper, str_is_alpha_num, str_shuffle_words, str_wordify, str_plurial, str_camel, str_snake, str_contains, str_capitalize, str_random, str_force_in_utf8, e, str_fix_utf8

Email​

email, raw_email

Other​

debug, sep, collect, trans, t, __

Usage​

app​

This helper gives you access to the BowPHP container.

app("mail");

config​

Gives you access to the BowPHP configuration.

config("mail")

response​

Gives you access to an instance of \Bow\Http\Response::class. It must be used inside a controller. You can find more information about the available methods here

return response($content = "hello papac", $code = 200);

request​

Gives you access to an instance of \Bow\Http\Request::class. It must be used inside a controller. You can find more information about the available methods here

$name = request()->get("name");

json​

Lets you use the json method of \Bow\Http\Response::class. It must be used inside a controller.

return json(["name" => "papac"], $code = 200);
// {"name": "papac"}

download​

During a request, lets you download a file. It is bound to the \Bow\Http\Response::class class. It must be used inside a controller.

$file = "/path/to/file.png";
$filename = "photo.png";

return download($file, $filename);

set_status_code​

Lets you change the HTTP status code of the response. It is bound to the \Bow\Http\Response::class class. It must be used inside a controller.

set_status_code(404);

view​

Lets you compile a view in BowPHP.

return view("view.name", ["name" => "papac"], $code = 200);

session​

Lets you manipulate the session interface in BowPHP.

session($value, $default = null)
  • If no argument is passed, it retrieves the session instance.
  • If default is provided and the value does not exist, it will be returned as the fallback value.
  • If $value is an associative array, it will add this information to the session as key-value pairs.
cookie("name", "papac");
// papac

create_csrf_token​

create_csrf_token();
// papac

csrf_token​

$token = csrf_token();
// papac

csrf_field​

$field = csrf_field();
// <input type="hidden" name="token" value="token_value" />

method_field​

$method = method_field("DELETE")
// <input type="hidden" name="_method" value="DELETE" />

generate_token_csrf​

generate_token_csrf();
// papac

verify_csrf​

verify_csrf($token);
// bool

csrf_time_is_expired​

csrf_time_is_expired();
// bool

sanitize​

$name = sanitize("papa'c")
// papac

secure​

$name = request()->get("name");
// papac

set_header​

set_header("X-Token-API", $token);

get_header​

$token = get_header("X-Token-API");
// papac

redirect​

return redirect();
// papac

redirect_back​

return redirect_back();

send​

return send("hello papac");
// hello papac

curl​

curl("https://github.com/bowphp");

url​

$name = request()->get("name");
// papac

flash​

$name = request()->get("name");
// papac

validator​

$name = request()->get("name");
// papac

route​

$name = request()->get("name");
// papac

old​

$name = request()->get("name");
// papac

client_locale​

$name = request()->get("name");
// papac

https://github.com/bowphp/framework/blob/4.0/src/Support/helper.php

Is something missing?

If you run into problems with the documentation or have suggestions to improve the documentation or the project in general, please open an issue for us, or send a tweet mentioning the Twitter account @bowframework or directly on github.