Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added some of the HMVC documentation

Signed-off-by: dchill42 <dchill42@gmail.com>
  • Loading branch information...
commit 9a70b7d5ed75b8cc4a1b1dbbf42bd992ced964af 1 parent 05b13b5
Darren Hill authored October 02, 2012
43  user_guide_src/source/general/controllers.rst
Source Rendered
@@ -280,6 +280,47 @@ controller as specified in your application/config/routes.php file
280 280
 CodeIgniter also permits you to remap your URIs using its :doc:`URI
281 281
 Routing <routing>` feature.
282 282
 
  283
+Loading Sub-Controllers
  284
+=======================
  285
+
  286
+The Hierarchical aspect of CodeIgniter's HMVC pattern allows you to pass
  287
+control to another Controller to handle part of a task. This is achieved
  288
+by calling::
  289
+
  290
+	$this->load->controller('subhandler');
  291
+
  292
+The first parameter to the Controller loader function is a URI string,
  293
+just like those explained above, except you don't specify a host or
  294
+index.php. The previous example would run the same Controller function as::
  295
+
  296
+	example.com/index.php/subhandler/
  297
+
  298
+In fact, any Controller in your application may be run either from the
  299
+request URL or through the Controller loader. The difference is that the
  300
+Controller routed by the request has primary control over the whole
  301
+application, whereas one loaded afterwards plays a secondary role. In
  302
+order to identify which Controller was routed, it gets a special "handle"
  303
+on the CodeIgniter root object::
  304
+
  305
+	$this->routed;
  306
+
  307
+Any time a part of your application needs to reference the top Controller,
  308
+this is how to identify it. Likewise, if a Controller needs to determine
  309
+whether it has been routed or called somewhere in the hierarchy, it can
  310
+compare itself to the routed Controller object::
  311
+
  312
+	if ($this === $this->routed)
  313
+	{
  314
+		// We are the top Controller!
  315
+	}
  316
+	else
  317
+	{
  318
+		// Some other Controller called us to do a job
  319
+	}
  320
+
  321
+More information about loading Controllers is available on the
  322
+:ref:`Loader <load-controller>` page.
  323
+
283 324
 Class Constructors
284 325
 ==================
285 326
 
@@ -321,4 +362,4 @@ list.
321 362
 That's it!
322 363
 ==========
323 364
 
324  
-That, in a nutshell, is all there is to know about controllers.
  365
+That, in a nutshell, is all there is to know about controllers.
2  user_guide_src/source/index.rst
Source Rendered
@@ -40,7 +40,7 @@ Introduction
40 40
 - :doc:`overview/cheatsheets`
41 41
 - :doc:`overview/features`
42 42
 - :doc:`overview/appflow`
43  
-- :doc:`overview/mvc`
  43
+- :doc:`overview/hmvc`
44 44
 - :doc:`overview/goals`
45 45
 
46 46
 ********
29  user_guide_src/source/libraries/loader.rst
Source Rendered
@@ -6,7 +6,9 @@ Loader, as the name suggests, is used to load elements. These elements
6 6
 can be libraries (classes) :doc:`View files <../general/views>`,
7 7
 :doc:`Drivers <../general/drivers>`,
8 8
 :doc:`Helpers <../general/helpers>`,
9  
-:doc:`Models <../general/models>`, or your own files.
  9
+:doc:`Models <../general/models>`,
  10
+:doc:`Controllers <../general/controllers>`,
  11
+or your own files.
10 12
 
11 13
 .. note:: This class is initialized automatically by the system so there
12 14
 	is no need to do it manually.
@@ -203,6 +205,31 @@ specify it via the second parameter of the loading function::
203 205
 
204 206
 	$this->fubar->function();
205 207
 
  208
+.. _load-controller:
  209
+
  210
+$this->load->controller('controller_name', 'object_name', $call)
  211
+================================================================
  212
+
  213
+This function loads a sub-Controller and calls the appropriate function::
  214
+
  215
+	$this->load->controller('subhandler/task');
  216
+
  217
+The call above would load the Subhandler Controller, make it accessible as
  218
+$this->subhandler, and pass control to the task() function. You may also 
  219
+assign an alternate object name::
  220
+
  221
+	$this->load->controller('weirdness', 'normal');
  222
+
  223
+This would make the Weirdness Controller accessible as $this->normal, and
  224
+call its index() function.
  225
+
  226
+Sometimes, you may want to load the controller, but not call any of its
  227
+functions yet::
  228
+
  229
+	$this->load->controller('later', '', FALSE);
  230
+
  231
+You could then call $this->later->*some_function*() when the time is right.
  232
+
206 233
 $this->load->database('options', true/false)
207 234
 ============================================
208 235
 
56  user_guide_src/source/overview/appflow.rst
Source Rendered
@@ -14,10 +14,60 @@ The following graphic illustrates how data flows throughout the system:
14 14
    the normal system execution.
15 15
 #. Security. Before the application controller is loaded, the HTTP
16 16
    request and any user submitted data is filtered for security.
17  
-#. The Controller loads the model, core libraries, helpers, and any
18  
-   other resources needed to process the specific request.
  17
+#. The Controller loads the model, helpers, and any other resources
  18
+   needed to process the specific request. It may also load and run
  19
+   sub-Controllers to help handle the task at hand.
19 20
 #. The finalized View is rendered then sent to the web browser to be
20 21
    seen. If caching is enabled, the view is cached first so that on
21 22
    subsequent requests it can be served.
22 23
 
23  
-.. |CodeIgniter application flow| image:: ../images/appflowchart.gif
  24
+For those who want to fully understand the details of the CodeIgniter
  25
+application lifecycle, and especially those who wish to modify CodeIgniter's
  26
+behavior through :doc:`extensions <../general/core_classes>` and/or
  27
+:doc:`hooks <../general/hooks>`, the entire sequence follows:
  28
+
  29
+#. Assess environment, paths, and overrides in index.php and set path constants
  30
+#. Define CI version
  31
+#. Read config.php and autoload.php files from the application path
  32
+#. Apply $assign_to_config overrides if present
  33
+#. Autoload package paths
  34
+#. Load CodeIgniter extension class if present
  35
+#. Instantiate the CodeIgniter object
  36
+#. Register the exception handler
  37
+#. Disable magic quotes for PHP < 5.4
  38
+#. Load :doc:`Benchmark <../libraries/benchmark>` class
  39
+#. *Mark total execution start time*
  40
+#. *Mark base class loading start time*
  41
+#. Load :doc:`Config <../libraries/config>` class and pass the core config items established during
  42
+   bootloading (including $assign_to_config overrides)
  43
+#. Read constants.php file(s) from all the application/package paths
  44
+#. Autoload config files
  45
+#. Load :doc:`Hooks <../general/hooks>` class
  46
+#. *Call pre-system hook*
  47
+#. Load :doc:`Loader <../libraries/loader>` class and pass the base and application path lists with
  48
+   autoloaded package paths applied
  49
+#. Load **Utf8** class
  50
+#. Load :doc:`URI <../libraries/uri>` class
  51
+#. Load :doc:`Output <../libraries/output>` class (to be prepared for 404 output)
  52
+#. Load :doc:`Router <../general/routing>` class, set routing, and apply $routing overrides
  53
+#. *Call cache-override hook*, and if not overridden, check for cache
  54
+#. If a valid cache is found, send it to Output and jump to the
  55
+   display-override hook below
  56
+#. Load :doc:`Security <../libraries/security>` class
  57
+#. Load :doc:`Input <../libraries/input>` class
  58
+#. Load :doc:`Lang <../libraries/language>` class
  59
+#. Autoload helpers, languages, libraries, drivers, controllers, and models
  60
+   (in that order, and don't run controllers)
  61
+#. *Mark base class loading end time*
  62
+#. *Call pre-controller hook*
  63
+#. *Mark controller execution start time*
  64
+#. Load the routed controller (or 404 if not found)
  65
+#. *Call post-controller-constructor hook*
  66
+#. Call routed controller method (or _remap) (or 404 if not found)
  67
+#. **THE** :doc:`CONTROLLER <../general/controllers>` **RUNS**
  68
+#. *Mark controller execution end time*
  69
+#. *Call post-controller hook*
  70
+#. *Call display-override hook*, and if not overridden, display output
  71
+#. *Call post-system hook*
  72
+
  73
+.. |CodeIgniter application flow| image:: ../images/appflowchart.gif
16  user_guide_src/source/overview/at_a_glance.rst
Source Rendered
@@ -35,14 +35,16 @@ CodeIgniter is Fast
35 35
 Really fast. We challenge you to find a framework that has better
36 36
 performance than CodeIgniter.
37 37
 
38  
-CodeIgniter Uses M-V-C
39  
-======================
  38
+CodeIgniter Uses HMVC
  39
+=====================
40 40
 
41  
-CodeIgniter uses the Model-View-Controller approach, which allows great
42  
-separation between logic and presentation. This is particularly good for
  41
+CodeIgniter uses the Hierarchical Model-View-Controller approach, which allows
  42
+great separation between logic and presentation. This is particularly good for
43 43
 projects in which designers are working with your template files, as the
44  
-code these files contain will be minimized. We describe MVC in more
45  
-detail on its own page.
  44
+code these files contain will be minimized. With the hierarchical capability,
  45
+you can break your application down into modular components for better division
  46
+of labor and code reusability. We describe :doc:`HMVC <hmvc>` in more detail
  47
+on its own page.
46 48
 
47 49
 CodeIgniter Generates Clean URLs
48 50
 ================================
@@ -111,4 +113,4 @@ CodeIgniter has a Friendly Community of Users
111 113
 =============================================
112 114
 
113 115
 Our growing community of users can be seen actively participating in our
114  
-`Community Forums <http://codeigniter.com/forums/>`_.
  116
+`Community Forums <http://codeigniter.com/forums/>`_.
3  user_guide_src/source/overview/features.rst
Source Rendered
@@ -12,7 +12,7 @@ an app is to try it and get to know the code.
12 12
 encourage you to do just that. In the mean time here's a list of
13 13
 CodeIgniter's main features.
14 14
 
15  
--  Model-View-Controller Based System
  15
+-  Hierarchical Model-View-Controller Based System
16 16
 -  Extremely Light Weight
17 17
 -  Full Featured database classes with support for several platforms.
18 18
 -  Query Builder Database Support
@@ -43,4 +43,3 @@ CodeIgniter's main features.
43 43
 -  Flexible URI Routing
44 44
 -  Support for Hooks and Class Extensions
45 45
 -  Large library of "helper" functions
46  
-
24  user_guide_src/source/overview/mvc.rst → user_guide_src/source/overview/hmvc.rst
Source Rendered
... ...
@@ -1,12 +1,17 @@
1  
-#####################
2  
-Model-View-Controller
3  
-#####################
  1
+##################################
  2
+Hierarchical Model-View-Controller
  3
+##################################
4 4
 
5  
-CodeIgniter is based on the Model-View-Controller development pattern.
6  
-MVC is a software approach that separates application logic from
7  
-presentation. In practice, it permits your web pages to contain minimal
  5
+CodeIgniter is based on the Hierarchical Model-View-Controller development
  6
+pattern. HMVC is a software approach that separates application logic from
  7
+presentation and supports modular subdivisions of application code.
  8
+In practice, it permits your web pages to contain minimal
8 9
 scripting since the presentation is separate from the PHP scripting.
9 10
 
  11
+-  The **Hierarchy** is a collection of one or more Controllers, each
  12
+   potentially having its own Model(s) and/or View(s). Program flow may
  13
+   be passed from the initial Controller down to other Controllers in
  14
+   any kind of hierarchy or sequence you wish.
10 15
 -  The **Model** represents your data structures. Typically your model
11 16
    classes will contain functions that help you retrieve, insert, and
12 17
    update information in your database.
@@ -25,3 +30,10 @@ ignore them and build your application minimally using Controllers and
25 30
 Views. CodeIgniter also enables you to incorporate your own existing
26 31
 scripts, or even develop core libraries for the system, enabling you to
27 32
 work in a way that makes the most sense to you.
  33
+
  34
+The Hierarchical aspect of CodeIgniter is similarly loose. Your application
  35
+may consist of a single Controller, as is seen in plain MVC, or any
  36
+number of Controllers organized any way you see fit. Models and Views
  37
+will likely be associated with specific Controllers, but each is accessible
  38
+to all parts of your application, thanks to the central CodeIgniter object
  39
+where every resource is registered.
2  user_guide_src/source/overview/index.rst
Source Rendered
@@ -12,5 +12,5 @@ The following pages describe the broad concepts behind CodeIgniter:
12 12
 	CodeIgniter Cheatsheets <cheatsheets>
13 13
 	Supported Features <features>
14 14
 	Application Flow Chart <appflow>
15  
-	Model-View-Controller <mvc>
  15
+	Model-View-Controller <hmvc>
16 16
 	Architectural Goals <goals>

0 notes on commit 9a70b7d

Please sign in to comment.
Something went wrong with that request. Please try again.