ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Modular Extensions - (HMVC) - Version 2.1.8

February 20, 2008 12:02am

Subscribe [6]
  • #46 / Feb 22, 2008 4:00am

    Rick Jolly

    729 posts

    What are modules, why should I use them?

    http://en.wikipedia.org/wiki/Module

    What is Modular HMVC, why should I use it?

    Modular HMVC = Multiple MVC triads

    This is most useful when you need to load a view and its data within a view. Think about adding a shopping cart to a page. The shopping cart needs its own controller which may call a model to get cart data. Then the controller needs to load the data into a view. So instead of the main controller handling the page and the shopping cart, the shopping cart MVC can be loaded directly in the page. The main controller doesn’t need to know about it, and is totally isolated from it.

    In CI we can’t call more than 1 controller per request. Therefore, to achieve HMVC, we have to simulate controllers. It can be done with libraries, or with this “Modular HMVC” contribution.

    EDIT:
    The differences between using a library and a “Modular HMVC” HMVC class is:
    1) No need to get and use the CI instance within an HMVC class
    2) HMVC classes are stored in a modules directory as opposed to the libraries directory.

    Is Modular HMVC the same as matchbox?

    Nope.

    Modular HMVC means modular MVC triads. Matchbox allows related controllers, models, libraries, views, etc. to be grouped together as a module - like a mini application.

  • #47 / Feb 22, 2008 4:08am

    Rick Jolly

    729 posts

    Nitpicking:

    The CI_Modules class should be a helper or a static class. All it does is load a HMVC class and run a method within that class. To create an instance of CI_Modules is unnecessary and calling it within a view is more verbose and less portable

    $this->modules->run('module',$data,'method');
    //vs a helper
    module_run('module',$data,'method');
    // or a static class (which can be a file in helpers and loaded just like a helper)
    module::run('module',$data,'method');

    edit: edited helper to be consistent

  • #48 / Feb 22, 2008 4:19am

    wiredesignz

    2882 posts

    Thanks Rick, in fact the whole library could be a helper. I’ll check out it’s functionality as a static helper.

  • #49 / Feb 22, 2008 5:01am

    wiredesignz

    2882 posts

    Modular HMVC now provides static functions to load and instantiate modules. Current version is now 2.0

    Thanks Rick Jolly. 😉

    $this->load->helper('modules');
    
    ...
    
    modules::load('widget');
    
    ...
    
    modules::run('widget', $data, $method);
  • #50 / Feb 22, 2008 5:10am

    xwero

    4145 posts

    Where is the latest library? Maybe you should create a wiki page or a page on your own server for more exposure   and easier access to the latest code.

  • #51 / Feb 22, 2008 5:13am

    wiredesignz

    2882 posts

    Check the first page of this thread again, I’m a bit slow doing updates tonight. 😉

    I don’t have a site (horror), and the wiki is so dis-organised things become obscure easily.

  • #52 / Feb 22, 2008 5:27am

    xwero

    4145 posts

    The firehouse/the furnace repository needs to be born soon 😛

  • #53 / Feb 22, 2008 7:03am

    badgeek

    26 posts

    very interesting! could you add more help in the documentation like usage and where to place modules

  • #54 / Feb 22, 2008 7:17am

    wiredesignz

    2882 posts

    The introduction has been modified to explain installation and usage. Thanks. 😉

  • #55 / Feb 22, 2008 7:36am

    badgeek

    26 posts

    im getting some weird error

    Fatal error: Class ‘odtest’ not found in W:\www\labs\app\helpers\modules_helper.php on line 57

    controller:

    function index()
        {
            $this->load->helper('modules');
            modules::load('Modtest');
            $this->load->view('welcome_message');
        }


    module

    class Modtest extends Modules
    {
        function Modtest()
        {
            parent::Modules();   
        }
    }

    am i doing wrong here?

    thanks

  • #56 / Feb 22, 2008 7:39am

    wiredesignz

    2882 posts

    modules extend the HMVC class

    class Modtest extends HMVC
    {
        function Modtest()
        {
            parent::HMVC();   
        }
    }

    Also make sure you have the most recent version. (like get it now)

  • #57 / Feb 22, 2008 7:44am

    badgeek

    26 posts

    changed the modules to

    class Modtest extends HMVC
    {
        function Modtest()
        {
            parent::HMVC();   
        }
    }

    but i still get

    Fatal error: Class ‘odtest’ not found in W:\www\labs\app\helpers\modules_helper.php on line 57

  • #58 / Feb 22, 2008 7:46am

    wiredesignz

    2882 posts

    Grab the latest version 2.0.2, I have changed the path extraction code

  • #59 / Feb 22, 2008 7:49am

    badgeek

    26 posts

    thanks, works great now! and make sure you add “?>” on the end of code 😛

  • #60 / Feb 22, 2008 7:54am

    gh0st

    130 posts

    Where is the wiki/documentation page for this? I want to know how to install and use it. 

    Sometimes its very hard to know what code is up to date, or find the latest versions.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases