Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这个问题只涉及 ThinkPHP 程序员。
所以在ThinkPHP中有Modeland 。D()模型对于与数据库进行通信非常有用。但是当我们使用D()创建一个Model然后找到一条数据。实际上我们得到的是一个数组。
Model
D()
那么我怎样才能得到一个属于一个类并且有方法可以使用的实例。在模型中构建方法似乎没有用。
除了模型,我是否应该有另一个类,例如UserModel.class+ User.class?</p>
UserModel.class
User.class
下面是我想到的。
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; } }