Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added more HMVC documentation

Signed-off-by: dchill42 <dchill42@gmail.com>
  • Loading branch information...
commit be13a3d14bfbbfa272c0e7b31a8bd96a209893ec 1 parent 9a70b7d
Darren Hill authored
15 user_guide_src/source/general/autoloader.rst
Source Rendered
@@ -2,19 +2,24 @@
2 2 Auto-loading Resources
3 3 ######################
4 4
5   -CodeIgniter comes with an "Auto-load" feature that permits libraries,
6   -helpers, and models to be initialized automatically every time the
  5 +CodeIgniter comes with an "Auto-load" feature that permits most
  6 +elements to be initialized automatically every time the
7 7 system runs. If you need certain resources globally throughout your
8 8 application you should consider auto-loading them for convenience.
9 9
10   -The following items can be loaded automatically:
  10 +The following items can be loaded automatically (in this order):
11 11
12   -- Core classes found in the "libraries" folder
13   -- Helper files found in the "helpers" folder
  12 +- Package Paths to include when loading (and autoloading) elements
14 13 - Custom config files found in the "config" folder
  14 +- Helper files found in the "helpers" folder
15 15 - Language files found in the "system/language" folder
  16 +- Library or Driver classes found in the "libraries" folder
  17 +- Controllers found in the "controllers" folder
16 18 - Models found in the "models" folder
17 19
  20 +Models and Controllers may also be autoloaded from your configured
  21 +:ref:`Module Path <hmvc-modules>`.
  22 +
18 23 To autoload resources, open the application/config/autoload.php file and
19 24 add the item you want loaded to the autoload array. You'll find
20 25 instructions in that file corresponding to each type of item.
7 user_guide_src/source/general/controllers.rst
Source Rendered
@@ -295,6 +295,10 @@ index.php. The previous example would run the same Controller function as::
295 295
296 296 example.com/index.php/subhandler/
297 297
  298 +.. note:: URIs used when loading a sub-Controller are also subject to
  299 + `URI Routing <routing>`_, and may be manipulated by custom routing
  300 + rules.
  301 +
298 302 In fact, any Controller in your application may be run either from the
299 303 request URL or through the Controller loader. The difference is that the
300 304 Controller routed by the request has primary control over the whole
@@ -319,7 +323,8 @@ compare itself to the routed Controller object::
319 323 }
320 324
321 325 More information about loading Controllers is available on the
322   -:ref:`Loader <load-controller>` page.
  326 +:ref:`Loader <load-controller>` page, and discussion of using Controllers
  327 +in HMVC modules can be found on the :ref:`HMVC <hmvc-modules>` page.
323 328
324 329 Class Constructors
325 330 ==================
15 user_guide_src/source/general/models.rst
Source Rendered
@@ -3,7 +3,7 @@ Models
3 3 ######
4 4
5 5 Models are **optionally** available for those who want to use a more
6   -traditional MVC approach.
  6 +traditional HMVC approach.
7 7
8 8 .. contents:: Page Contents
9 9
@@ -54,8 +54,8 @@ model class might look like::
54 54
55 55 }
56 56
57   -.. note:: The functions in the above example use the :doc:`Active
58   - Record <../database/query_builder>` database functions.
  57 +.. note:: The functions in the above example use the :doc:`Query
  58 + Builder <../database/query_builder>` database functions.
59 59
60 60 .. note:: For the sake of simplicity in this example we're using $_POST
61 61 directly. This is generally bad practice, and a more common approach
@@ -66,7 +66,10 @@ Anatomy of a Model
66 66 ==================
67 67
68 68 Model classes are stored in your **application/models/ folder**. They can be
69   -nested within sub-folders if you want this type of organization.
  69 +nested within sub-folders if you want this type of organization. They may also
  70 +be stored in the **models/** folder of a directory in your
  71 +:ref:`Module Path <hmvc-modules>`, where sub-folders lead to the module
  72 +directory instead of nesting inside the models/ subdirectory.
70 73
71 74 The basic prototype for a model class is this::
72 75
@@ -114,6 +117,10 @@ application/models/blog/queries.php you'll load it using::
114 117
115 118 $this->load->model('blog/queries');
116 119
  120 +This would also apply to a model in the blog/ directory inside your
  121 +:ref:`Module Path <hmvc-modules>`, which might be at
  122 +application/modules/blog/models/queries.php.
  123 +
117 124 Once loaded, you will access your model methods using an object with the
118 125 same name as your class::
119 126
8 user_guide_src/source/general/views.rst
Source Rendered
@@ -98,6 +98,14 @@ name loading the view. Example::
98 98
99 99 $this->load->view('folder_name/file_name');
100 100
  101 +This same notation also works for loading views from an
  102 +:ref:`HMVC Module <hmvc-modules>`, where the subdirectory name leads to
  103 +the module directory. For example, if you wanted to load a view from
  104 +application/modules/my_module/views/myview.php (assuming application/modules
  105 +is in your module path), you would load::
  106 +
  107 + $this->load->view('my_module/myview');
  108 +
101 109 Adding Dynamic Data to the View
102 110 ===============================
103 111
82 user_guide_src/source/overview/hmvc.rst
Source Rendered
@@ -36,4 +36,84 @@ may consist of a single Controller, as is seen in plain MVC, or any
36 36 number of Controllers organized any way you see fit. Models and Views
37 37 will likely be associated with specific Controllers, but each is accessible
38 38 to all parts of your application, thanks to the central CodeIgniter object
39   -where every resource is registered.
  39 +where every resource is registered.
  40 +
  41 +.. _hmvc-modules:
  42 +
  43 +Modules
  44 +=======
  45 +
  46 +A key feature of HMVC is support for modules, or groups of related MVC
  47 +components. If your application runs any sub-Controllers, it may be convenient
  48 +to keep their associated resources together with them in a subdirectory.
  49 +As common Models, Views, and Controllers are located in the application's
  50 +models/, views/, and controllers/ directories (with optional subdirectories
  51 +under those), another scheme is necessary to group functionally related
  52 +components together. The solution lies in the module path, which may contain
  53 +any hierarchy of module directories. Each module directory in the module path
  54 +is like a mini application folder - containing its own models/, views/, and
  55 +controllers/ directories.
  56 +
  57 +The default module path is application/modules, but you may configure a
  58 +different path or add more directories to the list in
  59 +application/config/config.php::
  60 +
  61 + $config['module_path'] = array('modules');
  62 +
  63 +Path directoriess may be absolute, relative to the PHP includes path, or
  64 +relative to your application directory (as is the default). Empty path
  65 +directories will not be searched, but subdirectories may be recursed with URI
  66 +segments in the request URL or with leading subdirectories when loading a
  67 +component directly. For example, if the module path is application/modules/,
  68 +then "foo/bar/baz" may map to any of these Controllers:
  69 +
  70 +* application/modules/controllers/foo.php
  71 +* application/modules/foo/controllers/bar.php
  72 +* application/modules/foo/bar/controllers/baz.php
  73 +* application/modules/foo/bar/baz/controllers/[default].php
  74 +
  75 +If you created a "foo" module in your module path (as in the second example
  76 +above), its directory structure might look like:
  77 +
  78 +* foo/
  79 +
  80 + * controllers/
  81 +
  82 + * bar.php
  83 +
  84 + * models/
  85 +
  86 + * foobar.php
  87 +
  88 + * views/
  89 +
  90 + * foo_menu.php
  91 + * bar.php
  92 +
  93 +You could run the Controller directly from the URL like this::
  94 +
  95 + example.com/index.php/foo/bar
  96 +
  97 +Or, perhaps more likely, you would call the index() function of your module
  98 +Controller from another Controller as follows::
  99 +
  100 + $this->load->controller('foo/bar');
  101 +
  102 +From within your Controller (or from any other part of your application, if
  103 +you wish), you would load your module Model like so::
  104 +
  105 + $this->load->model('foo/foobar');
  106 +
  107 +And then you could load your Views in the same manner::
  108 +
  109 + $this->load->view('foo/foo_menu');
  110 + $this->load->view('foo/bar');
  111 +
  112 +When loading MVC components from the module path, the search stops at the first
  113 +match found, so beware of naming conflicts. The main application directory
  114 +and any configured package paths are always searched first for Modules, Views,
  115 +and Controllers. (Remember that subdirectories apply _inside_ the component
  116 +directories here.) After that, module directories are searched in the order
  117 +specified in the module path. In the case of views, the $view_folder defined
  118 +in index.php (which becomes VIEWPATH) is always searched before even the
  119 +application directory.
2  user_guide_src/source/tutorial/index.rst
Source Rendered
@@ -3,7 +3,7 @@ Tutorial
3 3 ########
4 4
5 5 This tutorial is intended to introduce you to the CodeIgniter framework
6   -and the basic principles of MVC architecture. It will show you how a
  6 +and the basic principles of (H)MVC architecture. It will show you how a
7 7 basic CodeIgniter application is constructed in step-by-step fashion.
8 8
9 9 In this tutorial, you will be creating a **basic news application**. You
2  user_guide_src/source/tutorial/static_pages.rst
Source Rendered
@@ -14,7 +14,7 @@ For example, when a call is made to:
14 14 ``http://example.com/news/latest/10`` We might imagine that there is a
15 15 controller named "news". The method being called on news would be
16 16 "latest". The news method's job could be to grab 10 news items, and
17   -render them on the page. Very often in MVC, you'll see URL patterns that
  17 +render them on the page. Very often in (H)MVC, you'll see URL patterns that
18 18 match:
19 19 ``http://example.com/[controller-class]/[controller-method]/[arguments]``
20 20 As URL schemes become more complex, this may change. But for now, this

0 comments on commit be13a3d

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