Welcome Guest, Not a member yet? Register   Sign In
Modular Extensions - Version 4.3
#1

[eluser]wiredesignz[/eluser]
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

[eluser]wiredesignz[/eluser]
This quote may help explain the use of HMVC modules as posted by Rick Jolly. Thanks Rick Wink

[quote author="Rick Jolly" date="1203688844"]
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.[/quote]
#3

[eluser]sikkle[/eluser]
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 Smile

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

[eluser]wiredesignz[/eluser]
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:
Code:
$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:
Code:
$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:
Code:
return $this->load->view('partial', $data)
Using a Module as a view partial from within a view is as easy as writing:
Code:
<?php echo modules::run('module_name', $data, 'method_to_call') ?>

Hope this helps also.
#5

[eluser]wiredesignz[/eluser]
Version 4.0.4 includes changes to the modules::run() method
Code:
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:
Code:
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

[eluser]sikkle[/eluser]
Just thanks buddy, great great addition.

see ya around
#7

[eluser]wiredesignz[/eluser]
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

[eluser]Avatar[/eluser]
yeah for cheesy Smile 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

[eluser]wiredesignz[/eluser]
$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) Wink
#10

[eluser]wiredesignz[/eluser]
My plan is to create a non-invasive MY_Router extension which will allow modules to run directly from the URL.
Code:
http://domain.tld/module/method/data




Theme © iAndrew 2016 - Forum software by © MyBB