summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/general/ancillary_classes.rst
diff options
context:
space:
mode:
authorKyle Farris <kylefarris@kylefarris.gotdns.org>2011-10-14 21:43:25 +0200
committerKyle Farris <kylefarris@kylefarris.gotdns.org>2011-10-14 21:43:25 +0200
commitad17f4b932b3728c1e299b48f28b3ae0dbdd6b0b (patch)
treefdb357433e76000bdef60c4d18e5ab0540b07aeb /user_guide_src/source/general/ancillary_classes.rst
parentdb46d02ac23b8e0bc2416e197494d3b795b57530 (diff)
parenta2125a5d830fd390b4cf35f77e9bb0558cfa2dd7 (diff)
Merged with development
Diffstat (limited to 'user_guide_src/source/general/ancillary_classes.rst')
-rw-r--r--user_guide_src/source/general/ancillary_classes.rst49
1 files changed, 49 insertions, 0 deletions
diff --git a/user_guide_src/source/general/ancillary_classes.rst b/user_guide_src/source/general/ancillary_classes.rst
new file mode 100644
index 000000000..f7c87011b
--- /dev/null
+++ b/user_guide_src/source/general/ancillary_classes.rst
@@ -0,0 +1,49 @@
+##########################
+Creating Ancillary Classes
+##########################
+
+In some cases you may want to develop classes that exist apart from your
+controllers but have the ability to utilize all of CodeIgniter's
+resources. This is easily possible as you'll see.
+
+get_instance()
+===============
+
+**Any class that you instantiate within your controller functions can
+access CodeIgniter's native resources** simply by using the
+get_instance() function. This function returns the main CodeIgniter
+object.
+
+Normally, to call any of the available CodeIgniter functions requires
+you to use the $this construct::
+
+ $this->load->helper('url');
+ $this->load->library('session');
+ $this->config->item('base_url');
+ // etc.
+
+$this, however, only works within your controllers, your models, or your
+views. If you would like to use CodeIgniter's classes from within your
+own custom classes you can do so as follows:
+
+First, assign the CodeIgniter object to a variable::
+
+ $CI =& get_instance();
+
+Once you've assigned the object to a variable, you'll use that variable
+*instead* of $this::
+
+ $CI =& get_instance();
+
+ $CI->load->helper('url');
+ $CI->load->library('session');
+ $CI->config->item('base_url');
+ // etc.
+
+.. note:: You'll notice that the above get_instance() function is being
+ passed by reference::
+
+ $CI =& get_instance();
+
+ This is very important. Assigning by reference allows you to use the
+ original CodeIgniter object rather than creating a copy of it.