This chapter covers the CI helpers topic, the different types of helpers, and their different usage categories, with several code examples of web applications. CI provides us with built-in helpers, enables us to integrate third-party helpers, and enables us to develop new helpers and share them with the community if we wish to. The CI helpers are powering CI efficiency and code reusability by enabling all other CI controllers using the same code instead of defining a helper function locally.
A helper file is a collection of independent procedural functions in a particular category. Each helper function performs one specific task, with no dependence on other functions. The chapter will elaborate on the CI helper's concept, definition, and usage with several examples.
The folder system/helpers
contains the CI system's built-in helpers. The folder application/helpers
contains all the additional helper files of CI helpers. They can be third-party helpers or created by the developer.
This chapter will primarily focus on:
my_download
helperWe will begin by briefly reviewing what a helper is in a CI framework, and how we can use it for our needs across the project code resources.
The CI helper does not have access to the controller resources by default unless CI and get_instance()
are called and used to access CI resources.
We can extend the CI helper using third-party helpers from the CI system' or we can develop our own helper.
Any application helper should be located under application/helpers/
in the project directory.
The helper file must be in the following format:
application/helpers/<HELPER_NAME>_helper.php
For example, the SSL helper file should appear as application/helpers/ssl_helper.php
.
The helper integration and usage within the CI project is as follows:
application/helpers/myhelper_helper.php
myhelper
for all CI projects as follows:$autoload['helper'] = array('url','myhelper'),
$this->load->helper('myhelper'),
$result = $this->myhelper->called_method($param1, aram2);
CI and the CI developers community network provide many helpers, covering a rich set of topics. We will review CI helpers as well as popular resources for third-party CI helpers.
We are also encouraged to build our own helpers, which can be used by others, and share them with the following communities:
Git
community: https://github.com52.14.151.45