Blog Archive

Friday 24 August 2012

Advanced modules with simple module admin in FUEL CMS

I’ve been tempted lately to turn some of the simple FUEL CMS modules I’ve created into “advanced” modules. Partly I’ve wanted to do this to improve my understanding of Fuel, and partly because the concept of advanced modules make a lot of sense from a modularity and re-use point of view. Advanced modules are mini-applications, with their own contained controllers, models, views and assets. By copying their root folder, you have the entire file-set, rather than having to rummage in the applications directory for config, libraries, models and so on. It’s just so much more tidy!

When I began doing this with a simple “news” module, I reached a point where I thought I might have to re-create the simple module admin CRUD and I despaired a bit. I’d written a dashboard for an advanced module before (the configuration form for an import of the Sphider index engine) but that really required a custom input. Would the simple module admin (handled by FUEL’s module controller) really need some ugly, complicated retrofitting?

Fortunately no!! Here’s what I found, and again, FUEL allows an elegant stress free solution. If you follow the tutorials on www.getfuelcms.com, you’ll know that simple modules are recognised by the FUEL admin system when the appropriate array is added to MY_fuel_modules.php, eg:

   1:  $config['modules']['news'] = array(
   2:          'display_field' => 'title',
   3:          'instructions' => '',
   4:          'archivable' => TRUE,
   5:          'preview_path' => 'news/item/{id}'
   6:          ); 

By default, the model for this module will be found in /application/models. By specifying a “model_location” key, the model can instead be found in its advanced module location in /fuel/modules/news/models (in this example) eg:

   1:  $config['modules']['news'] = array(
   2:          'model_location' => 'news', // Looks for model in /modules/
   3:          ...
   4:          ); 

So now, the admin navigation link for Modules/News points to the ordinary CRUD pages, just as if the module were just a “simple” one.

You may already have an array in MY_fuel.php for the same advanced module to appear as a navigable module in its own right too eg:

   1:  $config['modules_allowed'] = array(
   2:      'user_guide',
   3:      'news'
   4:  );

Well, simply remove that module name. Be aware that doing so will remove advanced module functionality (eg prevent config & constants being loaded) from the admin, but if you have no use for these, it's no loss. Then you will have a simple module admin CRUD for an advanced module. The navigation should look something like:

module_nav_01




Note that you can reverse this navigation arrangement if you want. That is, you can retain the advanced module entry in the admin, and not have the simple module navigation, but still make use of the simple modules controller CRUD.

To do this, hide the simple module by adding this key to the module array in MY_fuel_modules.php:

   1:  $config['modules']['news'] = array(
   2:          'hidden' => TRUE,
   3:          ...
   4:          ); 

and add the module name back to the “modules_allowed” array in MY_fuel.php. This will automatically create an admin link as per the {module}.php file array in the advanced modules /config folder eg:

   1:  $config['nav']['news'] = array(
   2:          'news' => 'news'
   3:  );

which will point to url fuel/news, thus being an identical route to the default CRUD pages. The navigation will look like:

module_nav_02

However, since that link is pretty much all that’s needed, a navigation entry of News/news seems redundant. But if you do need the advanced module for custom dashboards as well as a link to the default CRUD system, this is the way to go.

I used v1.0 beta of FUEL CMS for this investigation, but I think the same methods hold true for v0.93.

I've written a more in-depth guide to FUEL advanced modules here

2 comments:

  1. Thanks for your pretty explanation but can i do MVC by codeigniter and move it to admin area of fuel ??? and How i do this safely ??

    ReplyDelete
    Replies
    1. If you have a model from Codeigniter, you can incorporate it into Fuel's admin using MY_fuel_modules.php. However, you would want to make the Model an extension of Fuel's Base Module Model Class, as that will provide the methods used throughout the admin for listing and CRUD functionality, I'd recommend reading:

      http://docs.getfuelcms.com/general/models
      &
      http://docs.getfuelcms.com/modules/simple

      Understanding the procedures in those articles will prove very helpful. If you want to make a self-contained, portable module, then the section in the Fuel docs for "advanced" modules is worth a read: http://docs.getfuelcms.com/modules/advanced

      Delete

My top artists