How to use helper function in codeigniter 4 - deesoft service

How to use helper function in codeigniter 4

Deepak Tailor Image
Deepak Tailor - Sep 22 2020
How to use helper function in codeigniter 4

Helpers are functions that help in your code. There are some helpers in codeigniter 4 like html helper, URL helper, from helper, text helper, cookie helper and many more. The work of all helpers is different. Such as linking css files in html helper work view file, creating URL helper work link, form helper's work building form.

We can also make helper custom. Who does his according work.

How to create custom helper

The custom helper we save is named filename_helper.php. Create this file in a folder containing helpers.

// helper expample

user_helper.php
profile_helper.php
admin_helper.php

helpers/user_helper.php
helpers/profile_helper.php
helpers/admin_helper.php
How to load helper in controller file

The helper can also be loaded anywhere in the controller. For example:

// load single helper in controller

helper('text');
helper('from');
helper('url');

// text helper example
echo word_limiter('my name is deepak tailor',4);
// output : my name is deepak...

// from helper example
echo form_open('home/submit_form');
echo form_close();

// url helper example
echo base_url();
// output : my name is deepak...

// load multiple helpers in controllers with array
helper(['text','from','url']);
Deepak Tailor Image
Deepak Tailor

My name is Deepak tailor as a fullstack developer. I have been in the IT industry (PHP, Nodejs, flutter) for the last 5 years. For professional and customize web development & app development, you can send inquiry on our email.
----
You can contact him at deepaktailor10@yahoo.in