CodeIgniter Basic Tutorial
Performance & Utilities
CodeIgniter Advanced
In CodeIgniter, a Helper is simply a collection of PHP functions (not classes) that make your work easier by providing shortcuts for common tasks.
👉 Think of a helper like a toolbox: whenever you need a small tool (like a URL formatter, string handler, or date formatter), you just open the toolbox and use it.
Helpers are stored in:
system/Helpers/ (Core helpers provided by CodeIgniter itself) app/Helpers/ (Custom helpers you create for your own project)
You can load a helper in two ways:
helper('url');
After this, you can immediately use URL functions like base_url()
.
Edit this file:
app/Config/Autoload.php
public $helpers = ['url', 'form'];
Now, the url
and form
helpers will load automatically for all controllers/views.
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') |
👉 This is useful when generating links dynamically.
👉 Instead of writing long HTML forms, helpers give you shortcuts.
You can create your own helpers if you need custom utility functions.
Example: app/Helpers/custom_helper.php
Load & Use: