Codeigniter Create Core System Classes
Every time CodeIgniter runs there are many base categories that are initialized mechanically as a part of the core framework.
It is potential, however, to swap any of the core system categories along with your own versions or perhaps extend the core versions.
Most users can ne'er have to need to try and do this, however, the choice to exchange or extend them will exist for those that would really like to considerably alter the CodeIgniter core.
System Class List
The following could be a list of the core system files that are invoked anytime CodeIgniter runs:
- Benchmark
- Config
- Controller
- Exceptions
- Hooks
- Input
- Language
- Loader
- Log
- Output
- Router
- Security
- URI
- Utf8
How to replace Core Class
To use one in every of your own system categories rather than a default one merely place your version within your native application/core/ directory:
Any file named identically to at least one from the list higher than are going to be used rather than the one commonly used.
Please note that your category should use CI as a prefix.
For example, if your file is called Input.php the category is going to be named:
<?php
class CI_Input {
}
Extending Core Class
-
If all you would like to try {and do} is add some practicality to an existing library - maybe add a way or 2 - then it’s overkill to interchange the complete library
-
with your version.
-
In this case, it’s higher to easily extend the category.
-
Extending a class is nearly identical to replacing a class with a couple of exceptions:
-
The class declaration must extend the parent class.
-
Your new category name and file name should be prefixed with Mya (this item is configurable.
-
See below.).
For example, to increase the native Input category you’ll produce a file named application/core/MY_Input.php, and declare your category with:
<?php
class MY_Input extends CI_Input {
}
<?php
class MY_Input extends CI_Input {
public function __construct()
{
parent::__construct();
// Your own constructor code
}
}
Tip: Any functions in your class that is named identically to the methods in the parent class will be used instead of the native ones (this is known as “method overriding”). This allows you to substantially alter the CodeIgniter core.
If you're extending the Controller core category, then make sure to increase your new category in your application controller’s constructors.