Welcome Guest, Not a member yet? Register   Sign In
Can a model use another model?
#1

[eluser]HugoA[/eluser]
I have a model class that make all the data base operations, but i want that model to use another class and put all the data from the data base in some variables, then, i just send to the controller an array of mi object.

for example:

this is the class

Code:
<?php

class Person extends Model{
    
    private $name;
    private $lastname;
    private $password;
    
    
    public function getName()
    {
        return $this->name;
    }
    
    function setName($data)
    {
        $this->name = $data;
    }
    
    public function getLastname()
    {
        return $this->lastname;
    }
    
    public function setLastname($data)
    {
        $this->lastname = $data;
    }
    
    public function getPassword()
    {
        return $this->password;
    }
    
    public function setPassword($data)
    {
        $this->password = $data;
    }
    
}

?>

and this is the model
Code:
<?php

class Formulario_model extends Model{
    
    function obtener_usuario()
    {
        $this->db->where('idpersona','1');
        $query = $this->db->get('persona');
        if($query->num_rows() > 0){
            foreach($query->result() as $row){
                $this->load->model('person');
                $this->person->setName($row->name);
            }
            return $data;
        }
    }
    
}

?>

if i do this i get this error

Fatal error: Call to a member function setName() on a non-object in C:\Aplicaciones\formulario\system\application\models\formulario_model.php on line 13

how can i solve this?
thanks


Messages In This Thread
Can a model use another model? - by El Forum - 01-13-2010, 04:15 PM
Can a model use another model? - by El Forum - 01-13-2010, 04:22 PM
Can a model use another model? - by El Forum - 01-13-2010, 07:35 PM



Theme © iAndrew 2016 - Forum software by © MyBB