Welcome Guest, Not a member yet? Register   Sign In
Model like Class
#1

[eluser]mestresan[/eluser]
Hi people...

I have problems and doubts about how to use model.
In general, I am creating model like a class, with properties, methods.
There are class that property are object from another class (model), ex:

Code:
class Customer extends CI_Model {

    protected $user_obj;
    protected $country_obj;
    ...

    function __construct()
    {
        parent::__construct();
        
        $this->load->model('domains/domain_model', 'domain_obj');
        // this case I load model because need tables name and other info from domain
        ....
    }
}

class Domain extends CI_Model {

    protected $title;
    protected $user;
    ...

    function __construct()
    {
        parent::__construct();
        
        $this->load->model('customers/customer_model');
        // this case I load model customer because I want that property "$user" to be a object from class model customer, so, I have all methods and properties in object
        ....
    }
}

in some cases.... first model load second model in construct, and second load first again.... occurs looping.

Fine....

What is the best method for this purpose?

thx in advance
#2

[eluser]toopay[/eluser]
Create a "global" model class (with MY_ prefix), which have all resource needed, and extend other model to it.
#3

[eluser]JonoB[/eluser]
And only have one class (model) per file.




Theme © iAndrew 2016 - Forum software by © MyBB