Skip to content
Browse files

Added more HMVC documentation

Signed-off-by: dchill42 <dchill42@gmail.com>
  • Loading branch information...
1 parent 9a70b7d commit be13a3d14bfbbfa272c0e7b31a8bd96a209893ec @dchill42 committed Oct 2, 2012
View
15 user_guide_src/source/general/autoloader.rst
@@ -2,19 +2,24 @@
Auto-loading Resources
######################
-CodeIgniter comes with an "Auto-load" feature that permits libraries,
-helpers, and models to be initialized automatically every time the
+CodeIgniter comes with an "Auto-load" feature that permits most
+elements to be initialized automatically every time the
system runs. If you need certain resources globally throughout your
application you should consider auto-loading them for convenience.
-The following items can be loaded automatically:
+The following items can be loaded automatically (in this order):
-- Core classes found in the "libraries" folder
-- Helper files found in the "helpers" folder
+- Package Paths to include when loading (and autoloading) elements
- Custom config files found in the "config" folder
+- Helper files found in the "helpers" folder
- Language files found in the "system/language" folder
+- Library or Driver classes found in the "libraries" folder
+- Controllers found in the "controllers" folder
- Models found in the "models" folder
+Models and Controllers may also be autoloaded from your configured
+:ref:`Module Path <hmvc-modules>`.
+
To autoload resources, open the application/config/autoload.php file and
add the item you want loaded to the autoload array. You'll find
instructions in that file corresponding to each type of item.
View
7 user_guide_src/source/general/controllers.rst
@@ -295,6 +295,10 @@ index.php. The previous example would run the same Controller function as::
example.com/index.php/subhandler/
+.. note:: URIs used when loading a sub-Controller are also subject to
+ `URI Routing <routing>`_, and may be manipulated by custom routing
+ rules.
+
In fact, any Controller in your application may be run either from the
request URL or through the Controller loader. The difference is that the
Controller routed by the request has primary control over the whole
@@ -319,7 +323,8 @@ compare itself to the routed Controller object::
}
More information about loading Controllers is available on the
-:ref:`Loader <load-controller>` page.
+:ref:`Loader <load-controller>` page, and discussion of using Controllers
+in HMVC modules can be found on the :ref:`HMVC <hmvc-modules>` page.
Class Constructors
==================
View
15 user_guide_src/source/general/models.rst
@@ -3,7 +3,7 @@ Models
######
Models are **optionally** available for those who want to use a more
-traditional MVC approach.
+traditional HMVC approach.
.. contents:: Page Contents
@@ -54,8 +54,8 @@ model class might look like::
}
-.. note:: The functions in the above example use the :doc:`Active
- Record <../database/query_builder>` database functions.
+.. note:: The functions in the above example use the :doc:`Query
+ Builder <../database/query_builder>` database functions.
.. note:: For the sake of simplicity in this example we're using $_POST
directly. This is generally bad practice, and a more common approach
@@ -66,7 +66,10 @@ Anatomy of a Model
==================
Model classes are stored in your **application/models/ folder**. They can be
-nested within sub-folders if you want this type of organization.
+nested within sub-folders if you want this type of organization. They may also
+be stored in the **models/** folder of a directory in your
+:ref:`Module Path <hmvc-modules>`, where sub-folders lead to the module
+directory instead of nesting inside the models/ subdirectory.
The basic prototype for a model class is this::
@@ -114,6 +117,10 @@ application/models/blog/queries.php you'll load it using::
$this->load->model('blog/queries');
+This would also apply to a model in the blog/ directory inside your
+:ref:`Module Path <hmvc-modules>`, which might be at
+application/modules/blog/models/queries.php.
+
Once loaded, you will access your model methods using an object with the
same name as your class::
View
8 user_guide_src/source/general/views.rst
@@ -98,6 +98,14 @@ name loading the view. Example::
$this->load->view('folder_name/file_name');
+This same notation also works for loading views from an
+:ref:`HMVC Module <hmvc-modules>`, where the subdirectory name leads to
+the module directory. For example, if you wanted to load a view from
+application/modules/my_module/views/myview.php (assuming application/modules
+is in your module path), you would load::
+
+ $this->load->view('my_module/myview');
+
Adding Dynamic Data to the View
===============================
View
82 user_guide_src/source/overview/hmvc.rst
@@ -36,4 +36,84 @@ may consist of a single Controller, as is seen in plain MVC, or any
number of Controllers organized any way you see fit. Models and Views
will likely be associated with specific Controllers, but each is accessible
to all parts of your application, thanks to the central CodeIgniter object
-where every resource is registered.
+where every resource is registered.
+
+.. _hmvc-modules:
+
+Modules
+=======
+
+A key feature of HMVC is support for modules, or groups of related MVC
+components. If your application runs any sub-Controllers, it may be convenient
+to keep their associated resources together with them in a subdirectory.
+As common Models, Views, and Controllers are located in the application's
+models/, views/, and controllers/ directories (with optional subdirectories
+under those), another scheme is necessary to group functionally related
+components together. The solution lies in the module path, which may contain
+any hierarchy of module directories. Each module directory in the module path
+is like a mini application folder - containing its own models/, views/, and
+controllers/ directories.
+
+The default module path is application/modules, but you may configure a
+different path or add more directories to the list in
+application/config/config.php::
+
+ $config['module_path'] = array('modules');
+
+Path directoriess may be absolute, relative to the PHP includes path, or
+relative to your application directory (as is the default). Empty path
+directories will not be searched, but subdirectories may be recursed with URI
+segments in the request URL or with leading subdirectories when loading a
+component directly. For example, if the module path is application/modules/,
+then "foo/bar/baz" may map to any of these Controllers:
+
+* application/modules/controllers/foo.php
+* application/modules/foo/controllers/bar.php
+* application/modules/foo/bar/controllers/baz.php
+* application/modules/foo/bar/baz/controllers/[default].php
+
+If you created a "foo" module in your module path (as in the second example
+above), its directory structure might look like:
+
+* foo/
+
+ * controllers/
+
+ * bar.php
+
+ * models/
+
+ * foobar.php
+
+ * views/
+
+ * foo_menu.php
+ * bar.php
+
+You could run the Controller directly from the URL like this::
+
+ example.com/index.php/foo/bar
+
+Or, perhaps more likely, you would call the index() function of your module
+Controller from another Controller as follows::
+
+ $this->load->controller('foo/bar');
+
+From within your Controller (or from any other part of your application, if
+you wish), you would load your module Model like so::
+
+ $this->load->model('foo/foobar');
+
+And then you could load your Views in the same manner::
+
+ $this->load->view('foo/foo_menu');
+ $this->load->view('foo/bar');
+
+When loading MVC components from the module path, the search stops at the first
+match found, so beware of naming conflicts. The main application directory
+and any configured package paths are always searched first for Modules, Views,
+and Controllers. (Remember that subdirectories apply _inside_ the component
+directories here.) After that, module directories are searched in the order
+specified in the module path. In the case of views, the $view_folder defined
+in index.php (which becomes VIEWPATH) is always searched before even the
+application directory.
View
2 user_guide_src/source/tutorial/index.rst
@@ -3,7 +3,7 @@ Tutorial
########
This tutorial is intended to introduce you to the CodeIgniter framework
-and the basic principles of MVC architecture. It will show you how a
+and the basic principles of (H)MVC architecture. It will show you how a
basic CodeIgniter application is constructed in step-by-step fashion.
In this tutorial, you will be creating a **basic news application**. You
View
2 user_guide_src/source/tutorial/static_pages.rst
@@ -14,7 +14,7 @@ For example, when a call is made to:
``http://example.com/news/latest/10`` We might imagine that there is a
controller named "news". The method being called on news would be
"latest". The news method's job could be to grab 10 news items, and
-render them on the page. Very often in MVC, you'll see URL patterns that
+render them on the page. Very often in (H)MVC, you'll see URL patterns that
match:
``http://example.com/[controller-class]/[controller-method]/[arguments]``
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.