Advanced Modules
Think of Advanced Modules as another application folder that can contain it's own controllers, helpers, libraries, language and view files. They can also contain their own assets folders. FUEL itself is an advanced module as is this user_guide module. It is highly recommended that you take a peek at this module's files and any others to get a sense of how to create one (it's not too tough!).
Generating an Advanced Module
FUEL comes with the ability to automatically generate the starter files for an advanced module. Below is an example of how to do so:
php index.php fuel/generate/advanced examples
Read more about FUEL's generate capabilities.
Steps to Create an Advanced Module Manually
- Create a folder to contain your code in the fuel/modules/ folder
- Create your config folder and add a {module_name}.php, {module_name}_constants.php, and a {module_name}_routes.php
- In the {module_name}.php config file, add your module specific configuration information as well as any FUEL admin interface information like:
$config['nav']['tools']['tools/{module_name}'] = '{module_name}';
This will create a menu {module_name} in the admin left navigation with a FUEL admin link of tools/{module_name}.As another example, let's look at the blog's configuration file found under fuel/modules/blog/config/blog.php:
$config['nav']['blog'] = array( 'blog/posts' => 'Posts', 'blog/categories' => 'Categories', 'blog/comments' => 'Comments', 'blog/links' => 'Links', 'blog/users' => 'Authors', 'blog/settings' => 'Settings' );
This will create the following in the admin left navigation.
<li><a href="http://localhost/fuelcmsdemo/index.php/fuel/blog/posts" class="ico ico_blog_posts">Posts</a></li> <li><a href="http://localhost/fuelcmsdemo/index.php/fuel/blog/categories" class="ico ico_blog_categories">Categories</a></li> <li><a href="http://localhost/fuelcmsdemo/index.php/fuel/blog/comments" class="ico ico_blog_comments">Comments</a></li> <li><a href="http://localhost/fuelcmsdemo/index.php/fuel/blog/links" class="ico ico_blog_links">Links</a></li> <li><a href="http://localhost/fuelcmsdemo/index.php/fuel/blog/users" class="ico ico_blog_users">Authors</a></li> <li><a href="http://localhost/fuelcmsdemo/index.php/fuel/blog/settings" class="ico ico_blog_settings">Settings</a></li>
You can overwrite the configuration values by adding your own application/config/{module}.php file with the specific values you want to overwrite.
- In the {module_name}_constants.php file its a good idea to create the following constants (although not required):
- {MODULE_NAME}_VERSION - the version number of the module
- {MODULE_NAME}_FOLDER - the folder name of the module
- {MODULE_NAME}_PATH - the full directory path to the module folder
- In the routes file, add the fuel routes you want to use. For example, this user_guide module has the following routes:
- $route[FUEL_ROUTE.'tools/user_guide'] = 'user_guide';
- $route[FUEL_ROUTE.'tools/user_guide/(:any)'] = 'user_guide/$1';
- In the {module_name}.php config file, add your module specific configuration information as well as any FUEL admin interface information like:
- Create your controller files.
- Admin Controllers - Pages that need to be displayed in the admin interface should inherit from the fuel/modules/fuel/libraries/Fuel_base_controller.php OR fuel/modules/fuel/controllers/module.php (which inherits from Fuel_base_controller) and can use the _validate_user(), protected controller method.
- Dashboard Controller - If you add a controller with the name of Dashboard, then it can get pulled in to the FUEL admin (if the module is in the fuel $config['dashboards'] configuration)
- Create your assets folder and add any specific styles you want to use for that module's admin interface in a css/{module_name}.css file including your menu item icons.
- If you have the Tester module, you can add your tests to a tests folder.
- If you have this user_guide module installed, you can add documentation to the views/_docs/ folder. There needs to be at least an index.php file before it will appear in the user_guide module.
- Last but not least, in order to see your module you must add the folder name of your module to the $config['modules_allowed'] array in your fuel/application/config/MY_fuel.php file.
Loading Module Assets
Loading module assets can be done one of two ways in your module controllers:
- $this->load->library('my_module/my_lib');
- $this->load->module_library('my_module', 'my_lib');