Part of the EllisLab Network
   
1 of 11
1
Modular Extensions - (HMVC) - Version 2.1.8
Posted: 19 February 2008 11:02 PM   [ Ignore ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1832
Joined  06-10-2007

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 | Validation Callbacks into Models | View Object PHP5 | Read the User Guide

Profile
 
 
Posted: 20 February 2008 01:27 AM   [ Ignore ]   [ # 1 ]  
Grad Student
Avatar
Rank
Total Posts:  71
Joined  11-25-2007

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

Profile
 
 
Posted: 20 February 2008 07:09 AM   [ Ignore ]   [ # 2 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  244
Joined  02-13-2008

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.

Profile
 
 
Posted: 20 February 2008 07:22 AM   [ Ignore ]   [ # 3 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  286
Joined  12-25-2007

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

 Signature 

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

Profile
 
 
Posted: 20 February 2008 07:38 AM   [ Ignore ]   [ # 4 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1832
Joined  06-10-2007

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

Rick Jolly - 22 February 2008 03: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 | Validation Callbacks into Models | View Object PHP5 | Read the User Guide

Profile
 
 
Posted: 20 February 2008 07:45 AM   [ Ignore ]   [ # 5 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  286
Joined  12-25-2007

Hey man, could you help me on this?

http://codeigniter.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://codeigniter.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?

Profile
 
 
Posted: 20 February 2008 07:46 AM   [ Ignore ]   [ # 6 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  244
Joined  02-13-2008

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

Profile
 
 
Posted: 20 February 2008 07:54 AM   [ Ignore ]   [ # 7 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  286
Joined  12-25-2007

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?

Profile
 
 
Posted: 20 February 2008 08:05 AM   [ Ignore ]   [ # 8 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  244
Joined  02-13-2008

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

Profile
 
 
Posted: 20 February 2008 08:12 AM   [ Ignore ]   [ # 9 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1832
Joined  06-10-2007

@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 | Validation Callbacks into Models | View Object PHP5 | Read the User Guide

Profile
 
 
Posted: 20 February 2008 08:29 AM   [ Ignore ]   [ # 10 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  244
Joined  02-13-2008

@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();
}

Profile
 
 
   
1 of 11
1
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 62592 Total Logged-in Users: 20
Total Topics: 77063 Total Anonymous Users: 1
Total Replies: 416222 Total Guests: 159
Total Posts: 493285    
Members ( View Memberlist )