From 8ede1a2ecbb62577afd32996956c5feaf7ddf9b6 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 5 Oct 2011 13:34:52 -0500 Subject: replacing the old HTML user guide with a Sphinx-managed user guide --- .../source/general/ancillary_classes.rst | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 user_guide_src/source/general/ancillary_classes.rst (limited to 'user_guide_src/source/general/ancillary_classes.rst') 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..29f176004 --- /dev/null +++ b/user_guide_src/source/general/ancillary_classes.rst @@ -0,0 +1,41 @@ +########################## +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. -- cgit v1.2.3-24-g4f1b From af8da30f5ef4420029fa71bef4d703192ccc3436 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 5 Oct 2011 17:40:07 -0500 Subject: fixing code block spacing on caching, ancillary class, and alternative php docs --- user_guide_src/source/general/ancillary_classes.rst | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'user_guide_src/source/general/ancillary_classes.rst') diff --git a/user_guide_src/source/general/ancillary_classes.rst b/user_guide_src/source/general/ancillary_classes.rst index 29f176004..f7c87011b 100644 --- a/user_guide_src/source/general/ancillary_classes.rst +++ b/user_guide_src/source/general/ancillary_classes.rst @@ -17,7 +17,10 @@ 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->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 @@ -30,12 +33,17 @@ First, assign the CodeIgniter object to a variable:: 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. + $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(); + $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. -- cgit v1.2.3-24-g4f1b