Welcome Guest, Not a member yet? Register   Sign In
Modular Extensions - HMVC version 5.2

is there a way to load a modules model into a library?

I've tried using:

$this->ci->load->model('media/media_model', NULL, FALSE);

With no joy.

I used to use a modified version of this library that could do this but you'd have to put the modules name at the end.

for example
$this->ci->load->model('media_model', NULL, FALSE, 'media');

After installing Modular Extensions it seems that {elapsed_time} doesn't work anymore Smile. Any tips ?


I have 2 controller module access:

The library MX_Controller.php I have 3 objects:

Base parent Controller
Frontend parent Base
Backend parent Base

Initializing controller access checking constructor function get_parent_class($this);

Controller access.php parent class Frontend

Controller admin.php parent class Frontend and class Backend.
I need to inherit only the Backend. How to do this?

@CoolGoose, The elapsed time bug is resolved in the latest version of Modular Extensions - HMVC.

@Enshteyn, I assume that English is not your native language but could you please try to explain your problem more clearly.

I think both will understand =)


@Enshteyn, Your image shows procedural code inside each class, but not inside a class method, this is impossible.

Modular Extensions HMVC version 5.2.15 is now available on the wiki.

Updated to allow access to module resources when using get_instance() within libraries.

Hi wiredesignz,

Thank you again for all your great work. You, and ofcourse derek jones, are my true heroes.

Today i looked into PDO, that i want to use in my codeigniter applications in the near future.

The next story is how i just did this. Please have a look at it, comments are really appreciated. (I will explain everything at very low level, so other users can follow along and use it as well)

So i begun with another clean codeigniter installation, and i installed the latest version, 5.2.15, of HMVC.

After that, i looked into the forums and wiki, if there were any good topic about integrating PDO into codeigniter.
I've found some topics about SQlite 3 and PDO (http://codeigniter.com/wiki/PDO_SQLite3/), but this is really bad practise, because one of the main purposes of pdo is that you can change dbdriver when you have to. And with this method, you are forced to use SQlite.. (not that sqlite is bad, but there are plenty of examples we need to use another dbdriver)

After that i saw this topic: PDO in Codeigniter.
It works fine ofcourse, but i really don't want to mess in one of the system files (DB.php). Because there might be a situation pdo will not be used or DB.php will be overwritten by accident when updating to the next version.

Next moment i thought: I'll write MY_Loader.php and edit the database functions.
But 1 sec later I thought, ofcourse, the database functions in MY_Loader.php are not used because I have the custom Controller from HMVC were the database function is added...

So i came with the following solution. I want to ask you kindly to review my solution and look if my solution is good practise at all? And if it might be integrated into the next version of HMVC (with some modifications ofcourse if necessary). I really appreciate your comments.

First, I modified the database function in the HMVC's Controller.php

/** Load the database drivers OR the PDO object **/
    public function database($params = '', $return = FALSE, $active_record = FALSE) {
        if (class_exists('CI_DB', FALSE) AND $return == FALSE AND $active_record == FALSE)
        // Start modification Modular Extensions to allow PDO
        if($db[$active_group]['pdo'] === TRUE)
            $DB = new PDO(
                    $db[$active_group]['dbdriver'] . ':host=' .
                    $db[$active_group]['hostname'] . ';dbname=' .
            if ($return === TRUE)
                return $DB;
            CI::$APP->db = $DB;
            return CI::$APP->db;
        // End modification

        require_once BASEPATH.'database/DB'.EXT;

        if ($return === TRUE)
            return DB($params, $active_record);
        CI::$APP->db = DB($params, $active_record);
        return CI::$APP->db;

Second, I added an extra option to the $db array in application/config/database.php

$db['default']['pdo']      = TRUE;

Now i can use PDO in my models like this:

function show_categories()
        $active = 1;
        $query  = "
            SELECT        *
            FROM         Categorie
            WHERE        categorieActive = :active
                         ORDER BY        categorieOrder
        $stmt = $this->db->prepare($query);
        $stmt->bindParam(':active', $active, PDO::PARAM_INT);
        $result = $stmt->fetchAll();

        return $result;

This will return an object with all the results.

First you add next line to your controller method:

$data['categorie'] = $this->home_model->show_categories();

And next you can use it in your view:

    foreach($categorie as $cat)
        echo '<h3>' . $cat->categorieTitle . '</h3>';
        echo '<p>' . $cat->categorieText . '</p>';

Everything is up and working. And i really see a hugh drop in the benchmarking from 0.0380 to 0.0278. (but that could be just lucky since these tests are not scientifically proven after all).

I'll hope everything in this topic is well written so everybody in the community could understand it. Please wiredesignz feel free to look into this and tell me of this code could be improved in any kind of way.

Thanks again and good night for everybody Smile

Hi CtheB, I can see you've put some effort into this but I can't help wondering if this might be better suited to a separate library that uses something like the "factory" design pattern to generate PDO objects and replace $db as needed.


You are one step in front of me.
I like to take it step for step.

Next step was to make it into a seperate library with a "PDOFactory" class and some Object Relational Mapping classes.

But that is not where i was talking about now.
You need to take into account that not everybody will understand all of this directly.

So i'll like to first to look at my post before. Is the code o.k. or do you think it could be improved?

When we agreed on that we could take it to the next step and look at the factory thing.

Do you have any suggestion how to communicate in the Controller class with the Factory classes?

Theme © iAndrew 2016 - Forum software by © MyBB