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]
  • #1 / Feb 20, 2008 12:02am

    wiredesignz

    2882 posts

    Version 2.1.8 of the Modular Extensions (HMVC) system incorporates ideas presented by the community in this thread.

    The system enables you to create modules which can operate as psuedo-controllers and have access to the core classes loaded in the current CI instance.

    Modules can be autoloaded when the modules helper is loaded. Create a modules.php file in application/config. Add your entries as needed.

    Modular Extensions (HMVC) code has been relocated to the CodeIgniter Wiki: Modular Extensions - (HMVC)

  • #2 / Feb 20, 2008 2:27am

    SpooF

    170 posts

    Very nice, I’ll give this a shot.  😝

  • #3 / Feb 20, 2008 8:09am

    Sam Dark

    242 posts

    Considering views. I want to render partial from a module. Why do I need to load a module in controller first(using autoload is not always good)?

    In my dumb-helper approach it’s instantiated and runned when called from view or controller.

  • #4 / Feb 20, 2008 8:22am

    Edemilson Lima

    241 posts

    Really great job! It deserves a page in the Wiki. 😊

  • #5 / Feb 20, 2008 8:38am

    wiredesignz

    2882 posts

    This quote may help explain the use of HMVC modules as explained 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 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.

    Q. Is Modular HMVC the same as matchbox?

    A. 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.

  • #6 / Feb 20, 2008 8:45am

    Edemilson Lima

    241 posts

    Hey man, could you help me on this?

    http://ellislab.com/forums/viewthread/69213/

    It is an example of client side cache control, which I think would be great for CodeIgniter. Well, I don’t care about the credits. If you do a good job on this, as you did in the library above, I will be plenty satisfyed with a new good add-on for our loved framework.

    I tested my example and it works, but it is just a test, it is not ready for CodeIgniter. Also it have a problem with Internet Explorer. When you try to reload an updated page, the browser should discard the page in its cache and loads the new page from the server cache. In Firefox this is working fine, but in IE it is always getting an 304 Not Modified header. I did not figure out what is wrong, so more testes must be made. Maybe another HTTP header related to expire date must be sent to IE in order to this work, I don’t know.


    Also, I would like to hear your opinion on this issue:

    http://ellislab.com/forums/viewthread/67663

    Should we extend the database library to get a non-private function for $this->db->_fetch_assoc() or $this->db->_fetch_object() and use them in our views? But the User Guide says that the Database classes can not be extended or replaced… What can we do?

  • #7 / Feb 20, 2008 8:46am

    Sam Dark

    242 posts

    @wiredesignz: why? I have 3 different layouts in my application (I’m using my own View layout library). Every layout contains 2-3 different widgets. So, to implement this with your approach I have to load different modules in each controller or autoload models that aren’t needed in current layout.

  • #8 / Feb 20, 2008 8:54am

    Edemilson Lima

    241 posts

    What you need to load (or autoload) is only the module library. Well, this is what I understood.

  • #9 / Feb 20, 2008 9:05am

    Sam Dark

    242 posts

    @Edemilson Lima: I haven’t tested it yet but look at the example:

    First loading product_list.

    $this->load->library['modules'];       //or in autoload.php
    $this->modules->load('product_list'];


    And only after that we can use our partial.

    <?php echo $this->product_list->render($catcode); ?>

    I want to avoid loading product_list in controller at all.

  • #10 / Feb 20, 2008 9:12am

    wiredesignz

    2882 posts

    @Sam: Edmilison is correct, only the modules library needs autoloading. Every widget should have its own HMVC controller, load them only when you need to.

    You could use an autoload method for the modules library, so it will load and output a widget with one call.

    function run($module, $config = FALSE)
    {
        $this->load($module, $config);
        $this->ci->$module->render();
    }
    
    ...
    
    <?php $this->modules->run('widget'); ?>

    @Edmilison: I’m not really up to speed on the issues you posted about, but I’ll take a look.

  • #11 / Feb 20, 2008 9:29am

    Sam Dark

    242 posts

    @wiredesignz: That’s what I’ve pointed to. Here is the helper:

    hmvc_helper.php

    function hmvc($module, $config = false){
      /* @var CI CI_Base */        
      $CI = &get;_instance();
      $CI->modules->load($config);
      return $this->$module->render();
    }
  • #12 / Feb 20, 2008 9:33am

    wiredesignz

    2882 posts

    Why bother with helpers, the view can call the modules loader directly. Just put my function inside the Modules class definition.

  • #13 / Feb 20, 2008 9:35am

    Edemilson Lima

    241 posts

    $this->load->library('modules');       //or in autoload.php

    This you put in your controller constructor or in config/autoload.php

    $this->modules->load('product_list');
    <?php echo $this->product_list->render($catcode); ?>

    I think you can put the $this->modules->load(‘product_list’) into your view, but instead of using a render() method in your module, you must use its constructor. I don’t want to load the modules from my controllers too. When I load a view, it is up to the view to load the modules it may have.


    @wiredesignz: Thank you!

  • #14 / Feb 20, 2008 9:39am

    wiredesignz

    2882 posts

    I wouldn’t load a module inside a view, and I wouldn’t use a helper, I would add a function to the class as I suggested. Do the whole thing with one line of code in the view.

    Using unecessary helpers is just code bloat.

  • #15 / Feb 20, 2008 9:57am

    Sam Dark

    242 posts

    @wiredesignz: agree. Please add it to an “official” piece of code.

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

ExpressionEngine News!

#eecms, #events, #releases