Codeigniter

CodeIgniter Helpers

Helper files are a collection of functions in a particular group. For example, CodeIgniter has a URL helper, which lets you easily print your website URL or the current URL, build links, and a few other functions too. Helpers can be used within Models, Controllers, and View files.
Helpers are not written in an object oriented format in the way that Controllers and Models are, they are simply a collection of procedural functions.
It can be in the system/helpers folder or in an application/helpers folder.

Loading a helper

Loading a helper is just like loading anything else in CodeIgniter; it takes just one line of code.

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

Loading multiple helpers

You can load multiple helpers by passing an array of values to the first parameter.

$this->load->helper( array('form', 'url', 'cookie') );

Using a helper

Because helper files are procedural files, you simply use the function in the same way as you call a standard PHP function, and not in the objective format as you would
with models.
For example, to echo your site URL using the URL helper, you would use:

<?php echo base_url(); ?>

“Extending” Helpers

Even though helpers are procedural files, you can extend them in a literal sense. To do this, create a file in the system/application/helpers/ folder, with the same name as a core CI helper with the prefix MY_. You can change this prefix, but we won’t go into that right now.
Then you simply create a function inside this file with the same name as the function that you wish to replace, or add a new function.
For example, if you wanted to extend the Form Helper, you would create a file called MY_form_helper.php inside the system/application/helpers/ folder, and create any functions that you wish to add.

Recommended Tutorials for you


Related posts

CodeIgniter Plugins

Anuj Kumar

Form Validation in CodeIgniter

Anuj Kumar

CodeIgniter View

Anuj Kumar

Validation rules to a config file in CodeIgniter

Anuj Kumar

CodeIgniter Model

Anuj Kumar

How to fetch data in CodeIgniter

Anuj Kumar

Active Record in CodeIgniter

Anuj Kumar

CodeIgniter Introduction

Anuj Kumar

CodeIgniter Controllers

Anuj Kumar

1 comment

How to create form in CodeIgniter - PHPGurukul November 15, 2018 at 7:14 pm

[…] For working with form in CodeIginter you have to use form helper. […]

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

This site uses Akismet to reduce spam. Learn how your comment data is processed.