0

This question concerns merely ThinkPHP programmers.

So there are Model and D() in ThinkPHP. A model is very useful to communicate with the DB. But when we use D() to create a Model then find a piece of data. actually what we get is a array.

Then how can I get a instance that is of a class and has methods to use. To build methods in the model seems useless.

Should I have another class apart from the model, for example UserModel.class + User.class

bijiDango
  • 1,385
  • 3
  • 14
  • 28

1 Answers1

0

Below is what I thought out.

class BasicModel extends Model
{

    protected $instance;

    public function loadInstance($id)
    {
        $this->instance = $this->find($id);
    }

    public function saveInstance()
    {
        if ($this->create($this->instance))
            return $this->add();
        return false;
    }
}
bijiDango
  • 1,385
  • 3
  • 14
  • 28