Ali
Ali

Reputation: 267077

How to Extend a Helper in CodeIgniter?

I want to add some new functions to the core string helper, which is found in system/helpers folder. I think there was a 'right' way to do this using MY_String_helper, or something of that sort. I can't remember exactly how it was done though. Any thoughts on this issue?

Upvotes: 14

Views: 9222

Answers (3)

user2067021
user2067021

Reputation: 4529

For a primary source, in case things change in the future, the CodeIgniter User Guide's Helpers page has a section describing how to extend helpers.

Upvotes: 1

Phil Sturgeon
Phil Sturgeon

Reputation: 30766

Doing that you can not only add new functions but replace exising helper functions.

Upvotes: 8

Ali
Ali

Reputation: 267077

I found it. Make a file with a name such as this, in the application/helpers directory:

MY_xx_helper.php

E.g:

MY_string_helper.php

Then you can call

$this->load->helper('string');

And it should load all the existing helper functions as well as the new ones you add.

Upvotes: 25

Related Questions