Skip to content

Commit 4ea4e86

Browse files
committed
docs: add "Creating Custom Helpers" and sample code
1 parent e359bc7 commit 4ea4e86

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

user_guide_src/source/general/helpers.rst

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,17 @@ URI to the controller/method you wish to link to.
172172
Creating Helpers
173173
****************
174174

175+
Creating Custom Helpers
176+
=======================
177+
175178
The helper filename is the **helper name** and **_helper.php**.
176-
For example, to create Email Helper, you’ll create a file named
177-
**app/Helpers/email_helper.php**.
179+
180+
For example, to create info helper, you’ll create a file named
181+
**app/Helpers/info_helper.php**, and add a function to the file:
182+
183+
.. literalinclude:: helpers/008.php
184+
185+
You can add as many functions as you like to a single helper file.
178186

179187
"Extending" Helpers
180188
===================
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
// app/Helpers/info_helper.php
4+
5+
/**
6+
* Returns CodeIgniter's version.
7+
*/
8+
function ci_version(): string
9+
{
10+
return CodeIgniter::CI_VERSION;
11+
}

0 commit comments

Comments
 (0)