CodeIgniter Basic Tutorial
Performance & Utilities
CodeIgniter Advanced
In CodeIgniter, a Helper is a collection of standalone functions that help you perform common tasks.
They are not classes — just PHP functions you can call anywhere after loading the helper.
Think of Helpers as "shortcuts" for repetitive tasks like working with URLs, strings, forms, dates, etc.
Helpers are stored in:
system/Helpers/ (Core helpers) app/Helpers/ (Custom helpers you create)
You can load a helper in two ways:
helper('url');
This loads the url_helper.php
file so you can use its functions.
Edit:
app/Config/Autoload.php public $helpers = ['url', 'form'];
This makes the helpers available everywhere without loading them manually.
Helper Name |
Purpose |
Example Function |
---|---|---|
url |
Work with URLs |
base_url('path') |
form |
Create form elements |
form_open('route') |
text |
Format and work with text |
word_limiter($string, 5) |
html |
Generate HTML elements |
img('path/to/image.jpg') |
date |
Format and manage dates |
now() |
number |
Format numbers |
number_to_currency(1500, 'USD') |
Load the helper:
helper('url');
Use the function:
echo base_url('products/view/10'); // Output: http://your-site.com/products/view/10
helper('form'); echo form_open('products/save'); echo form_input('name', 'Product Name'); echo form_submit('submit', 'Save'); echo form_close();
Example: app/Helpers/custom_helper.php
<?php function greet($name) { return "Hello, " . ucfirst($name) . "!"; }
Load & Use:
helper('custom'); echo greet('john'); // Output: Hello, John!