mirror of
https://github.com/bcit-ci/CodeIgniter.git
synced 2025-02-20 11:13:29 +08:00
...
parent
b989d7b7b8
commit
b609f497d1
@ -14,38 +14,20 @@ Also, I wanted as little impact on a standard CodeIgniter installation, as every
|
||||
- Supports routing to a module controller
|
||||
- Supports cross module calls, also to controller methods
|
||||
- Uses standard CodeIgniter routing, no Router library modifications
|
||||
- Introduces $this->load->module() via a Loader library extension
|
||||
- Support for both version 1.7.2 and 2.0
|
||||
- Support for the default index() method and the _remap() method
|
||||
|
||||
|
||||
[b]Solution:[/b]
|
||||
|
||||
The new Module library can be loaded from inside your controller, like any other library:
|
||||
[code]$this->load->library('module', array('path' => 'modules') );[/code]
|
||||
By default, Modular CI expends modules to be installed in the directory 'modules', in the same directory as your index.php. If you alter the location, you have to inform the loader that there is a different location. You do that via
|
||||
[code]// set the location of our modules
|
||||
$this->load->module_path( 'modules' );[/code]
|
||||
|
||||
You can pass a config array to the library to define the location of your modules. This path is relative to your application document root directory (the directory that holds your index.php file). You can also use a configuration file for this purpose.
|
||||
|
||||
You can also load the Module library via the autoload config file. If you do, you have to use a configuration file to inform the library of the location of your modules:
|
||||
[code]<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
/*
|
||||
| -------------------------------------------------------------------------
|
||||
| Modules path
|
||||
| -------------------------------------------------------------------------
|
||||
|
|
||||
| This variable must contain the name of your "modules" folder.
|
||||
| Include the path if the folder is not in the same directory
|
||||
| as you applications index.php file.
|
||||
|
|
||||
*/
|
||||
|
||||
$config['path'] = 'modules';
|
||||
|
||||
/* End of file module.php */
|
||||
/* Location: ./application/config/module.php */[/code]
|
||||
|
||||
Once the Module library is loaded, you can initialize a module by using:
|
||||
[code]// Make the "my_module" module available to us
|
||||
$this->module->load('my_module');[/code]
|
||||
Once the path is set, you can initialize a module by using:
|
||||
[code]// Make the "my_module" module available
|
||||
$this->load->module('my_module');[/code]
|
||||
|
||||
This is all you have to do. From this moment on, all files from this module can be accessed in a way similar to the way you would normally load them. Note that you don't have to load a library or a module before using it. It will be autoloaded as soon as you reference it:
|
||||
[code]// call a method in a library of our module
|
||||
|
Loading…
x
Reference in New Issue
Block a user