Welcome Guest, Not a member yet? Register   Sign In
Modular HMVC - Libraries on Steroids [Updated x3]
#1

[eluser]wiredesignz[/eluser]
My goal here was to produce a Modular HMVC library that does not require you to extend or change CI_Loader and is PHP4 compatible.

This library will allow modules to be loaded and used as though they were controllers, they inherit nearly all of the controller features.


This thread has been superseded
New details can be found here: http://ellislab.com/forums/viewthread/72123/
#2

[eluser]Référencement Google[/eluser]
It seems that you have an error while calling the line: $ci = &get;_instance();
I would do $ci =& get_instance();
Am I right?
#3

[eluser]wiredesignz[/eluser]
The forum script added the semi-colons.

EDIT: fix-ed, thanks elitemedia. Smile
#4

[eluser]Sam Dark[/eluser]
Good. Will try using this code istead of my helper.
#5

[eluser]wiredesignz[/eluser]
Added modules sub-directories.
Code:
$this->modules->load('dir/module');
#6

[eluser]Référencement Google[/eluser]
wiredesignz, excuse my ignorance, but what's the difference from the MatchBox library exactly? Can you post a concrete usage example?
#7

[eluser]wiredesignz[/eluser]
Matchbox is a great tool, but I wanted modular HMVC without altering the CI core libraries. (CI_Loader)

The Modules loader mimics CI's own method of loading Controllers and Models, by assigning all loaded libraries into the module namespace. Any further loads by the module are intercepted and passed to $CI to process, then the object namespace for the module is updated again.

Using the modules is easy.
This module creates a products_list based on a value obtained from the View data:

In the View template I have:
Code:
<p>Products in this Category</p>
    <ul id="products-list">
        &lt;?php $this->product_list->render($catcode); ?&gt;
    </ul>

The admin/products_list module
Code:
class Product_list extends Modules //as a psuedo-controller
{
    function Product_list()
    {
        parent::Modules();
        $this->load->model('products_model', 'products');
    }
    
    function render($catcode = 0)
    {        
        $this->products->findAll("catcode = {$catcode}");
        
        $data = array(
            'resultset' => & $this->products->resultset,
        );

        $this->load->view('admin/products_list', $data);
    }
}

The View partial for the admin/products_list:
Code:
&lt;?php
    foreach($resultset as $product => $item)
    {
        echo '<li>', anchor("admin/products/edit/{$item->product_id}", "{$item->description}", 'title="'.$item->name.'"'), '</li>';
    }
?&gt;
#8

[eluser]Référencement Google[/eluser]
Interresting, I bookmarked that and will give it a try on my next application developpement.
Thanks Wiredesignz
#9

[eluser]wiredesignz[/eluser]
Here I'm using a module to setup my login form validation.
Code:
class _login extends Modules //as a psuedo-controller
{
    var $username, $password, $remember;
    
    function _login()
    {
        parent::Modules();
        $this->load->library('validation');
        $this->setup();
    }
    
    function setup()
    {        
        $this->validation->set_error_delimiters('', '');
    
        $this->validation->set_fields(array(
            'username' => 'Username',
            'password' => 'Password',
            'remember' => 'Remember'
        ));
        
        $this->validation->set_rules(array(
            'username'     => 'trim|required',
            'password'     => 'trim|required',
            'remember'  => ''
        ));
    }
}
#10

[eluser]wiredesignz[/eluser]
Another thought came to mind where the Modules loader could be extended to load Models and Views etc from the Modules sub-directories in the same fashion as Matchbox.

That would be true modular separation.




Theme © iAndrew 2016 - Forum software by © MyBB