Load and use CI4 helpers (url, form, text, array) and create reusable custom helper files.
Helpers in CI4
// Load helpers
helper("url"); // url(), site_url(), base_url(), redirect()
helper("text"); // word_limiter(), character_limiter(), ellipsize()
helper("form"); // form_open(), form_input(), form_submit()
helper("date"); // now(), human_to_unix(), unix_to_human()
helper("array"); // array_from_prefix(), dot_array_search()
helper("security"); // sanitize_filename(), strip_image_tags()
// Auto-load helpers — app/Config/Autoload.php
public array $helpers = ["url", "form", "text"];
// Create custom helper — app/Helpers/my_helper.php
function format_phone(string $phone): string {
return preg_replace("/(d{3})(d{3})(d{4})/", "$1-$2-$3", $phone);
}
// Use in controller or view
helper("my");
echo format_phone("5551234567"); // 555-123-4567