EllisLab text mark
Advanced Search
1 of 8
1
   
Modular Extensions - (HMVC) - Version 2.1.8
Posted: 20 February 2008 12:02 AM
Avatar
Joined: 2007-06-10
2937 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)

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
Posted: 20 February 2008 02:27 AM   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-11-25
195 posts

Very nice, I’ll give this a shot.  tongue rolleye

 
Posted: 20 February 2008 08:09 AM   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2008-02-13
250 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.

 
Posted: 20 February 2008 08:22 AM   [ # 3 ]   [ Rating: 0 ]
Avatar
Joined: 2007-12-25
252 posts

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

 Signature 

Oh God… Why didn’t you show me CodeIgniter before?

 
Posted: 20 February 2008 08:38 AM   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2937 posts

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

Rick Jolly - 22 February 2008 09:00 AM

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.

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
Posted: 20 February 2008 08:45 AM   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2007-12-25
252 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?

 Signature 

Oh God… Why didn’t you show me CodeIgniter before?

 
Posted: 20 February 2008 08:46 AM   [ # 6 ]   [ Rating: 0 ]
Avatar
Joined: 2008-02-13
250 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.

 
Posted: 20 February 2008 08:54 AM   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2007-12-25
252 posts

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

 Signature 

Oh God… Why didn’t you show me CodeIgniter before?

 
Posted: 20 February 2008 09:05 AM   [ # 8 ]   [ Rating: 0 ]
Avatar
Joined: 2008-02-13
250 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.

 
Posted: 20 February 2008 09:12 AM   [ # 9 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2937 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.

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
Posted: 20 February 2008 09:29 AM   [ # 10 ]   [ Rating: 0 ]
Avatar
Joined: 2008-02-13
250 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();
 
Posted: 20 February 2008 09:33 AM   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2937 posts

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

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
Posted: 20 February 2008 09:35 AM   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2007-12-25
252 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!

 Signature 

Oh God… Why didn’t you show me CodeIgniter before?

 
Posted: 20 February 2008 09:39 AM   [ # 13 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2937 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.

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
Posted: 20 February 2008 09:57 AM   [ # 14 ]   [ Rating: 0 ]
Avatar
Joined: 2008-02-13
250 posts

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

 
Posted: 20 February 2008 10:22 AM   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2937 posts

Added. Thanks Sam, hope it’s of use. wink

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
1 of 8
1