From e334c472fb4be44feec3a73402fc4a2b062cbfc0 Mon Sep 17 00:00:00 2001
From: admin When we use the term "Libraries" we are normally referring to the classes that are located in the libraries
-directory and described in the Class Reference of this user guide. In this case, however, we will instead describe how you can create
-your own libraries within your application/libraries directory in order to maintain separation between your local resources
+directory and described in the Class Reference of this user guide. In this case, however, we will instead describe how you can create
+your own libraries within your application/libraries directory in order to maintain separation between your local resources
and the global framework resources. As an added bonus, Code Igniter permits your libraries to extend native classes if you simply need to add some functionality
+ As an added bonus, Code Igniter permits your libraries to extend native classes if you simply need to add some functionality
to an existing library. Or you can even replace native libraries just by placing identically named versions in your application/libraries folder.
In summary: Your library classes should be placed within your application/libraries folder, as this is where Code Igniter will look for them when
+ Your library classes should be placed within your application/libraries folder, as this is where Code Igniter will look for them when
they are initialized. Where someclass is the file name, without the ".php" file extension. You can submit the file name capitalized or lower case.
+ Where someclass is the file name, without the ".php" file extension. You can submit the file name capitalized or lower case.
Code Igniter doesn't care. Once loaded you can access your class using the lower case version:Creating Libraries
Storage
-
$this->load->library('someclass');
-
In the library loading function you can dynamically pass data via the second parameter and it will be passed to your class +
In the library loading function you can dynamically pass data via the second parameter and it will be passed to your class constructor:
@@ -178,7 +178,7 @@ This function returns the Code Igniter super object.
etc.
-$this, however, only works directly within your controllers, your models, or your views. +
$this, however, only works directly within your controllers, your models, or your views. If you would like to use Code Igniter's classes from within your own custom classes you can do so as follows:
@@ -231,7 +231,7 @@ Extending a class is nearly identical to replacing a class with a couple exceptiFor example, to extend the native Email class you'll create a file named application/libraries/MY_Email.php, and declare your class with:
@@ -261,7 +261,7 @@ to load the example above, which extends the Email class, you will use:$this->load->library('email');
-Once loaded you will use the class variable as you normally would for the class you are extending. In the case of +
Once loaded you will use the class variable as you normally would for the class you are extending. In the case of the email class all calls will use: -- cgit v1.2.3-24-g4f1b