diff options
author | admin <devnull@localhost> | 2006-10-21 00:16:54 +0200 |
---|---|---|
committer | admin <devnull@localhost> | 2006-10-21 00:16:54 +0200 |
commit | 0625e19f3318874d6f95b546312601538edb0f14 (patch) | |
tree | 9b7e301328b0c06367757be6b96fa74229452abb /user_guide/general | |
parent | 31eeb0587cd5fcef8209ca5083f28a39435c135d (diff) |
Diffstat (limited to 'user_guide/general')
-rw-r--r-- | user_guide/general/core_classes.html | 15 | ||||
-rw-r--r-- | user_guide/general/creating_libraries.html | 34 |
2 files changed, 38 insertions, 11 deletions
diff --git a/user_guide/general/core_classes.html b/user_guide/general/core_classes.html index 556a4efc3..6d2f3804f 100644 --- a/user_guide/general/core_classes.html +++ b/user_guide/general/core_classes.html @@ -113,11 +113,15 @@ class CI_Input {<br /><br /> <h2>Extending Core Class</h2>
<p>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.</p>
+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:</p>
-<p>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 <kbd>MY_</kbd>. For example, to extend the native <kbd>Input</kbd> class
-you'll create a file named <dfn>application/libraries/Input.php</dfn>, and declare your class with:</p>
+<ul>
+<li>The class declaration must extend the parent class.</li>
+<li>Your new class name and filename must be prefixed with <kbd>MY_</kbd> (this item is configurable. See below.).</li>
+</ul>
+
+<p>For example, to extend the native <kbd>Input</kbd> class you'll create a file named <dfn>application/libraries/</dfn><kbd>MY_Input.php</kbd>, and declare your class with:</p>
<code>
class MY_Input extends CI_Input {<br /><br />
@@ -135,7 +139,8 @@ class MY_Input extends CI_Input {<br /> }<br />
}</code>
-<p>Any functions in your class that are named identically to the functions in the parent class will be used instead of the native ones.
+<p class="important"><strong>Tip:</strong> 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 is known as "method overloading").
This allows you to substantially alter the Code Igniter core.</p>
diff --git a/user_guide/general/creating_libraries.html b/user_guide/general/creating_libraries.html index 3f168909d..d76464120 100644 --- a/user_guide/general/creating_libraries.html +++ b/user_guide/general/creating_libraries.html @@ -226,17 +226,24 @@ class CI_Email {<br /><br /> <h2>Extending Native Libraries</h2>
<p>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.</p>
+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:</p>
-<p>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 <kbd>MY_</kbd>. For example, to extend the native <kbd>Email</kbd> class
-you'll create a file named <dfn>application/libraries/Email.php</dfn>, and declare your class with:</p>
+<ul>
+<li>The class declaration must extend the parent class.</li>
+<li>Your new class name and filename must be prefixed with <kbd>MY_</kbd> (this item is configurable. See below.).</li>
+</ul>
+
+<p>For example, to extend the native <kbd>Email</kbd> class you'll create a file named <dfn>application/libraries/</dfn><kbd>MY_Email.php</kbd>, and declare your class with:</p>
<code>
class MY_Email extends CI_Email {<br /><br />
}</code>
+<p>Note: If you need to use a constructor in your class make sure you extend the parent constructor:</p>
+
+
<code>
class MY_Email extends CI_Email {<br />
<br />
@@ -246,9 +253,13 @@ class MY_Email extends CI_Email {<br /> }<br />
}</code>
-<p class="important"><strong>Important:</strong> To tell Code Igniter to load your sub-class you MUST include <kbd>my_</kbd> in the loading function:</p>
-<code>$this->load->library('<kbd>my_</kbd>email');</code>
+<h3>Loading Your Sub-class</h3>
+
+<p>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:</p>
+
+<code>$this->load->library('<kbd>email</kbd>');</code>
<p>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:
@@ -256,6 +267,17 @@ the email class all calls will use: <code>$this-><kbd>email</kbd>->some_function();</code>
+
+<h3>Setting Your Own Prefix</h3>
+
+<p>To set your own sub-class prefix, open your <dfn>application/config/config.php</dfn> file and look for this item:</p>
+
+<code>$config['subclass_prefix'] = 'MY_';</code>
+
+<p>Please note that all native Code Igniter libraries are prefixed with <kbd>CI_</kbd> so DO NOT use that as your prefix.</p>
+
+
+
</div>
<!-- END CONTENT -->
|