Difference between helper and library in CodeIgniter
CodeIgniter PHP Difference

Difference between helper and library in CodeIgniter

Mishel Shaji
Mishel Shaji

An essential part of CodeIgniter is libraries and helpers. They help you to easily develop a website.

What is a helper

Helpers are PHP files that contain some functions that help you to do specific tasks. For example, Email helper helps you to work with email by helping to validate or send emails.

Helpers are not written in Object Oriented format hence you can simply call helper functions in the same way you call usual PHP functions.

CodeIgniter does not load helpers by default. Therefore we need to load required helpers by using the following code.

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

Once loaded, helpers can be accessed anywhere in your code.

What are libraries

Libraries are located under system/libraries. CodeIgniter offers you the freedom to create, extend or replace libraries. Unlike helpers, libraries are not files that contain PHP functions. Libraries are Classes. therefore you need to make an instance of the class ($this->load->library()) to use it. And you’ll need to use the object of the class ($this->library_name->method()) to call the methods.

Difference between helpers and libraries

Now, let us find the difference between helpers and libraries.

Helpers

  • Helpers are located under system/helpers.
  • A helper is a file that contains some PHP functions.
  • It is not Object-Oriented.
  • A helper is loaded using $this->load->helper('helper name').
  • Helper functions can be called in the same way you call PHP functions.
  • All inbuilt helper files are suffixed with _helper in its name (eg: email_helper.php)

Libraries

  • Libraries are located under system/libraries.
  • A library is a class.
  • It is Object-Oriented.
  • A library is loaded using $this->load->library('library name').
  • You need to create an object of the class to call library functions. $this->library_name->method() .
  • All inbuilt library files do not have a specific suffix.