From 79c643da4efcf154254730d78c6532cff3d99d1e Mon Sep 17 00:00:00 2001
From: admin Every time Code Igniter runs there are several base classes that are initialized automatically as part of the core framework.
-It is possible, however, to swap any of the core system classes with your own versions. Most users will never have any need to do this,
-but the option to replace them does exist for those who would like to significantly alter the Code Igniter core.
+It is possible, however, to swap any of the core system classes with your own versions or even extend the core versions. Most users will never have any need to do this,
+but the option to replace or extend them does exist for those who would like to significantly alter the Code Igniter core.
Note: Replacing a core system class with your own version has a lot of implications, so make sure you
+ Note: Messing with a core system class has a lot of implications, so make sure you
know what you are doing before attempting it. If all you need to do is add some functionality to an existing library - perhaps add a function or two - then
+it's overkill to replace the entire library with your version. In this case it's better to simply extend the class. Extending a class is identical to replacing a class with one exception: The class declaration must extend the parent class
+and your new class must be prefixed with MY_. For example, to extend the native Input class
+you'll create a file named application/libraries/Input.php, and declare your class with: Note: If you need to use a constructor in your class make sure you extend the parent constructor: Any functions in your class that are named identically to the functions in the parent class will be used instead of the native ones.
+This allows you to substantially alter the Code Igniter core. The page below explains these three concepts in detail. Note: The Database classes can not be extended or replaced with your own classes,
+nor can the main Controller class. All other classes are able to be replaced/extended. Your library classes should be placed within your application/libraries folder, as this is where Code Igniter will look for them when
@@ -203,7 +207,7 @@ etc.
Simply by naming your class files identically to a native library will cause Code Igniter to use it instead of the native one. To use this
feature you must name the file and the class declaration exactly the same as the native library. For example, to replace the native Email library
-you'll create a file named application/libraries/email.php, and declare your class with:Creating Core System Classes
+Extending Core Class
+
+
+class MY_Input extends CI_Input {
+
+
+
+}
+class MY_Input extends CI_Input {
+
+
+
+ function My_Input()
+ {
+ parent::CI_Input();
+ }
+}Storage
class CI_Email {
@@ -216,6 +220,7 @@ class CI_Email {
$this->load->library('email');
+Note: At thit time the Database classes can not be replaced with your own versions.
Extending Native Libraries
@@ -225,15 +230,13 @@ it's overkill to replace the entire library with your version. In this case it'
Extending a class is identical to replacing a class with one exception: The class declaration must extend the parent class
and your new class must be prefixed with MY_. For example, to extend the native Email class
-you'll create a file named application/libraries/email.php, and declare your class with:
+you'll create a file named application/libraries/Email.php, and declare your class with:
class MY_Email extends CI_Email {
}
-Note: If you need to use a constructor in your class make sure you extend the parent constructor:
-
class MY_Email extends CI_Email {
@@ -249,6 +252,7 @@ class MY_Email extends CI_Email {
+
--
cgit v1.2.3-24-g4f1b