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 - Version 4.3

March 03, 2008 6:10pm

Subscribe [48]
  • #1 / Mar 03, 2008 6:10pm

    wiredesignz's avatar

    wiredesignz

    2882 posts

    This marks the release of Version 4 of Modular Extensions - HMVC. (4th re-write)

    Modular Extensions HMVC enables you to use self contained HMVC modules that can be accessed by Controllers, Models and Views.

    The scripts have been wriiten to be smaller, faster and to provide cascading file searching.

    $this->load->xxx() can be used withn modules just as within normal controllers.

    Version 4 is described on the wiki. Modular Extensions - HMVC

    Any feedback would be appreciated. Thanks for your interest.

  • #2 / Mar 03, 2008 7:03pm

    wiredesignz's avatar

    wiredesignz

    2882 posts

    This quote may help explain the use of HMVC modules as posted by Rick Jolly. Thanks Rick 😉

    Q. What are modules, why should I use them?

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

    Q. What is Modular HMVC, why should I use it?

    A. 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 Extensions HMVC” contribution.

    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.

    Q. Is Modular Extensions HMVC the same as Matchbox?

    A. Since version 3.0 it is.

    Modular HMVC means modular MVC triads. Matchbox and Modular Extensions allows related controllers, models, libraries, views, etc. to be grouped together in module directories and used like a mini application.

  • #3 / Mar 03, 2008 7:48pm

    sikkle

    325 posts

    Nice, i just give it a try, realy this is well done, simple and efficiant, this is a “real” addition to codeigniter.

    Just a suggestion for people, into the wiki, make it clear about the parent::module just to help noob 😊

    Also i have this setup :

    /application/public
    /application/private
    /modules/enjoy/controllers/enjoy.php

    Seem that the system is plan to work with one level only, if everythings is on the same stages.

    I’ll find my way to make it work, but i mean, maybe this is a suggestion to got the ability to control it.

    EDIT : i think it’s build and more logic to put it like this :

    /application/public
    /application/private
    /application/modules/enjoy/controllers/enjoy.php

    indeed that work just great!

    thanks a lot.

  • #4 / Mar 03, 2008 7:51pm

    wiredesignz's avatar

    wiredesignz

    2882 posts

    How it works!

    When CodeIgniter loads a controller it attaches its own core libraries to the controller so you are able access to them easily using methods such as:

    $this->uri or $this->load

    When a Module is loaded it is attached to the controller also and it uses references to these core libraries so they can also be called from within the module in the same manner as you would within the controller.

    As you load additional libraries or models within your Module the modules_helper attaches them to the Module for you, in the same manner as the CodeIgniter loader does for the controller.

    The controller also has access to these new libraries via the Module. ie:

    $this->module_name->library or $this->module_name->model

    View Partials

    When you create a view partial within a module it is best to `return` the view to the caller rather than displaying it directly from the Module otherwise you may get your partial displaying outside of the parent view.

    To prevent this happening, loading views within Modules is set by default to create a variable and should always be returned to the caller. ie:

    return $this->load->view('partial', $data)

    Using a Module as a view partial from within a view is as easy as writing:

    <?php echo modules::run('module_name', $data, 'method_to_call') ?>

    Hope this helps also.

  • #5 / Mar 03, 2008 11:38pm

    wiredesignz's avatar

    wiredesignz

    2882 posts

    Version 4.0.4 includes changes to the modules::run() method

    function run($module, $data = '', $method ='index')
    {
        $class =& modules::load($module);
        return (method_exists($class, $method))? $class->$method($data) : $class->_error($method);
    }

    And changes to the module class:

    class Module
    {
        function Module()
        {
            $ci =& get_instance();
            
            $this->load =& new Loader($this);
            $this->load->_assign_libraries($this, $ci);
            $this->load->_ci_assign_to_models();
            
            log_message('debug', ucfirst(get_class($this))." module initialised");
        } 
        
        function index()
        {
            log_message('error', ucfirst(get_class($this))." module: No index() method defined");
        }
        
        function _error($method)    //called by modules::run() if $method does not exist
        {
            log_message('error', ucfirst(get_class($this))." module: No ".$method."() method defined");
        }
    }
  • #6 / Mar 04, 2008 12:39am

    sikkle

    325 posts

    Just thanks buddy, great great addition.

    see ya around

  • #7 / Mar 04, 2008 2:29am

    wiredesignz's avatar

    wiredesignz

    2882 posts

    Helpful Hint:

    The modules helper has two debug methods you might like to look at.

    modules::debug($any_object); will display the $any_object and list its loaded libraries, using $this will display the current module.

    modules::debug_in($any_object) or modules::debug_in($any_array) will do a full dump on the subject.

    NOTE:
    If you debug_in() the CodeIgniter Core ($CI) you will get a page full of recursive arrays, this is not an issue because most of the recursions are only references back into $CI core objects.

  • #8 / Mar 04, 2008 2:32am

    Avatar's avatar

    Avatar

    198 posts

    yeah for cheesy 😊 I can see some nice app already. especially since I own the domain smellcheese.com, pauka. Thank you so much for this.

    when you say:

    $this->load->module->something is no longer required. $this->load->something can be used withn modules just as within normal controllers.

    does that mean that I won’t be able to use the $this->load->module->something in the future?

  • #9 / Mar 04, 2008 2:45am

    wiredesignz's avatar

    wiredesignz

    2882 posts

    $this->load->module->something still works so we keep backward compatibilty with Version 3.

    At some point I might change this so a module can be loaded in a controller by using $this->load->module(‘module_name’);

    It would be best if it was not used from this point forward. (So stuff doesn’t break later) 😉

  • #10 / Mar 04, 2008 2:55am

    wiredesignz's avatar

    wiredesignz

    2882 posts

    My plan is to create a non-invasive MY_Router extension which will allow modules to run directly from the URL.

    <a href="http://domain.tld/module/method/data">http://domain.tld/module/method/data</a>
  • #11 / Mar 04, 2008 3:05am

    Avatar's avatar

    Avatar

    198 posts

    would you say that is is best to load the modules via url in divs with scriptaculous or jquery or something. orhave a user module that does only user stuff and a home module and a admin module? I’m just trying to figure out how to really sturucture my app and how I will be passing data before I get really far into my app. TIA -A

  • #12 / Mar 04, 2008 3:10am

    wiredesignz's avatar

    wiredesignz

    2882 posts

    For Ajax interaction I would create a seperate media controller accessible from the URL which accepts calls and selects and runs the appropriate module.

    I would also have a public_controller with its modules to manage the website and a seperate admin_controller with its modules to manage the backend.

  • #13 / Mar 04, 2008 3:18am

    xwero

    4145 posts

    Wiredesignz hold the updates for a while 😛 For you know it the version number gets into the thousands. You know after version 7 or 8 you have to hire a marketing team to sell your software and they come up with the most ridiculous names 😊

    But seriously now you are changing peoples view on how to structure applications by being so committed to the library you create, i bow my head in the up most respect.

  • #14 / Mar 04, 2008 4:15am

    Avatar's avatar

    Avatar

    198 posts

    Yes, it it good. I can work it into any ci app. 100% yeah May I suggest version numbering in this form 4.1.1 small updated on the right rewrites in the center and major left I started ci since 1.3.1 and it has come a long way to 1.6.1 Thanks

  • #15 / Mar 04, 2008 5:49am

    Avatar's avatar

    Avatar

    198 posts

    what say you about adding a function to get the parent module name when loading a module from within a module with the directory structure below I have to modules::run(‘parent/modules/sibling/sibling’) and it works can we add a check or a function to get parent and current module for this behavior ?

    app/
        modules/
            parent/
                controllers/
                      parent.php
                modules/
                      sibling/
                          controllers/
                                sibling.php

    Thank you so much for this great lib. It’s the best I’ve found for ci in all 2 years I’ve used it. I only got 4 hours of sleep lasst night, but I googlemuch.com 😊

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

ExpressionEngine News!

#eecms, #events, #releases