^Status|Draft|
^Todo|Expand, Proof read|
====== Modules ======
Kohana is easily extendable using modules. Modules are reusable collections of related files that together add a particular functionality to an application. You may want to re-use some helpers or add authentication across multiple applications. Place it in a module folder and you can copy it with ease or have multiple applications use the same module directory.
The [[:general:filesystem|Filesystem]] page should be read before this one to understand it properly.
===== Setting up =====
It is most common to have a directory called ''modules'' in the same directory as the ''application'' and ''system'' directories. For instance, we created a module for ACL (access control lists) and authentication (auth) since we want to reuse it across applications.
root
+- application
+- system
+- modules
| +- acl
| | +- helpers
| | +- i18n
| | +- libraries
| | +- models
| | +- vendor
| | +- views
| |
| +- auth
| +- helpers
| +- i18n
| +- libraries
| +- models
| +- vendor
| +- views
|
+- index.php
===== Configuring =====
Only placing modules in the ''modules'' directory won't load them, they must be configured for Kohana to use them. This can be done in the ''application/config/config.php file'' using the 'modules' setting.
**Example**
// Paths are relative to the docroot, but absolute paths are also possible
// Use the MODPATH constant (?)
$config['modules'] = array
(
MODPATH.'acl',
MODPATH.'auth',
)
In the cascading [[:general:filesystem|filesystem]], files in modules that are higher up the list take precedence over those lower down just as files in the ''application'' directory do over those in modules and the ''system'' directory.