Welcome Guest, Not a member yet? Register   Sign In
Populating an array of objects using CI's load->model() functionality
#6

[eluser]vitoco[/eluser]
[quote author="Dan Horrigan" date="1271886118"]
A library is your best bet (a library is just a fancy name for a class anyway). Create a Details class that has all the properties you need. Then your container class can have an array of Detail classes. Each Details object would be a row from the database. The libraries can access the models that actually interface with the db (as long as you use use the get_instance() function).

Because the 2 classes are so closely tied, you can keep them both in the same file, that way you just load 1 library into your controller.

Dan[/quote]

Why use get_instance() from a library in order to access databases, if models do that with $this->db ??.

I think, that you must use one Model, or in the worst case, extends one model from the other, so you can get access to db, and return the data as you need.

MODEL 1
Code:
Class MTx_detail extends Model
{
    function MT_detail()
    {
        parent::Model();
    }

    function get_detail_tx()
    {
        ;
    }
}
MODEL 2
Code:
Class MTx extends MTx_detail
{
    function MTx()
    {
        parent::MTx_detail();
    }

    function get_header_tx()
    {
        ....
        ....
    }

    function get_data_tx()
    {
        .....
        $tx->header  = $this->get_header_tx();
        $tx->details = $this->get_detail_tx();
        ....
        return $tx ;
    }
}



IN THE CONTROLLER
Code:
...
$this->load->model('mtx_detail');
$this->load->model('mtx');
//
$tx = $this->mtx->get_data_tx();
...


Messages In This Thread
Populating an array of objects using CI's load->model() functionality - by El Forum - 04-21-2010, 05:00 PM



Theme © iAndrew 2016 - Forum software by © MyBB