From 37f4b9caa02783e06dd7c5318200113409a0deb1 Mon Sep 17 00:00:00 2001
From: Derek Jones 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
+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. The page below explains these three concepts in detail. Note: The Database classes can not be extended or replaced with your own classes. All other classes are able to be replaced/extended. Note: The Database classes can not be extended or replaced with your own classes. All other classes are able to be replaced/extended.Creating Libraries
Storage
@@ -88,16 +88,16 @@ they are initialized.
Classes should have this basic prototype (Note: We are using the name Someclass purely as an example):
+Classes should have this basic prototype (Note: We are using the name Someclass purely as an example):
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Someclass {
@@ -136,7 +136,7 @@ $this->load->library('Someclass', $params);
If you use this feature you must set up your class constructor to expect data:
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Someclass {
@@ -147,8 +147,8 @@ class Someclass {
}
?>
-You can also pass parameters stored in a config file. Simply create a config file named identically to the class file name
-and store it in your application/config/ folder. Note that if you dynamically pass parameters as described above,
+
You can also pass parameters stored in a config file. Simply create a config file named identically to the class file name
+and store it in your application/config/ folder. Note that if you dynamically pass parameters as described above,
the config file option will not be available.
@@ -202,7 +202,7 @@ etc.
Replacing Native Libraries with Your Versions
Simply by naming your class files identically to a native library will cause CodeIgniter 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
+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:
@@ -222,12 +222,12 @@ class CI_Email {
Extending Native Libraries
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.
+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 nearly identical to replacing a class with a couple exceptions:
- The class declaration must extend the parent class.
-- Your new class name and filename must be prefixed with MY_ (this item is configurable. See below.).
+- Your new class name and filename must be prefixed with MY_ (this item is configurable. See below.).
For example, to extend the native Email class you'll create a file named application/libraries/MY_Email.php, and declare your class with:
@@ -252,12 +252,12 @@ class MY_Email extends CI_Email {
Loading Your Sub-class
-To load your sub-class you'll use the standard syntax normally used. DO NOT include your prefix. For example,
+
To load your sub-class you'll use the standard syntax normally used. DO NOT include your prefix. For example,
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