Skip to content
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos
How to create custom helpers in CodeIgniter

How to create custom helper in CodeIgniter

Posted on June 6, 2018September 22, 2021 By XpertPhp No Comments on How to create custom helper in CodeIgniter

In this article, We will discuss how to create custom helper in CodeIgniter. CodeIgniter allows the creation of a custom helper. So we can easily create a custom helper. we will take the latest example and learn how to use a custom helper in CodeIgniter. so let’s follow the below step.

Step 1: Create the helper file.

first, we will create a helper file in the “application/helpers/commonfunction_helper.php”. put some code in this file. here this file. we will get the student all detail using the custom helper function.

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
/*
* get_all_rows
*
*/
function get_all_student_rows()
{
$CI =& get_instance();
$CI->db->select();
$query = $CI->db->get('students');
//echo $CI->db->last_query();die;
return $query->result_array(); // This will return array
}
?>

Step 2: Load The Custom helper

Now, we will load the custom helper so we will open the application/config/autoload.php file and add the helper name in the helper array.

PHP
1
2
3
4
5
6
7
8
9
/*
| -------------------------------------------------------------------
|  Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['helper'] = array('url', 'file');
*/
$autoload['helper'] = array('commonfunction_helper');

Step 3: How to use the custom helper function in Controller or Views.

now, we can use the custom helper function in Controller or Views. we can get the student detail in Controller or Views using the call get_all_rows helper function.

Controller Example

PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
 
class Student extends CI_Controller {
    function __construct()
    {
        parent::__construct();
    }
    public function index()
    {
      $student_detail = get_all_student_rows();
      echo "<pre>";
      print_r(student_detail);
      echo "</pre>";
    }
}

View Example

PHP
1
2
3
4
5
6
<?php
     $student_detail = get_all_student_rows();
     echo "<pre>";
     print_r(student_detail);
     echo "</pre>";
?>

So finally, I hope you like this article.

Please follow and like us:
error
fb-share-icon
Tweet
fb-share-icon

Recommended Posts:

  • login and registration example using pdo
  • Laravel 6 Pagination Example Tutorial
  • CodeIgniter 4 Ajax Form Submit Validation Example
  • How to create Pagination with Codeigniter and MySql
  • Codeigniter 4 Google Pie Chart Example
Codeigniter, MySql Tags:codeigniter helper, codeigniter tutorial

Post navigation

Previous Post: PHP Array convert into string
Next Post: CodeIgniter join query example

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tricks jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch Laravel Socialite laravel social login nodejs pagination payment gateway php with mysql react js tutorial rewrite rule send mail validation wysiwyg editor

Latest Posts

  • How to Convert Date and Time from one timezone to another in php
  • how to get current date and time in php
  • Drag and Drop Reorder Items with jQuery, PHP & MySQL
  • Laravel 9 Toastr Notifications Example Tutorial
  • Laravel 9 CRUD Operation Example Using Google Firebase
  • Laravel 9 CKeditor Image Upload With Example
  • Laravel 9 Summernote Image Upload With Example
  • Laravel 9 Stripe Payment Gateway Integrate Example
  • How To Send Email Using Mailtrap In Laravel 9
  • Laravel 9 Fullcalendar Ajax Example Tutorial

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Age Calculator Online
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Copyright © 2018 - 2022,

All Rights Reserved Powered by XpertPhp.com