【发布时间】:2011-05-26 16:07:04
【问题描述】:
在我习惯的 MVC 中,模型类(通常)表示表,这些类的对象是行/域对象。我在 CodeIgniter 中不明白为什么模型类看起来只是单例实用程序类。感觉写错了
$data = array('text' => 'hello');
$this->commentModel->insert($data);
而不是
$comment = new Comment();
$comment->text = 'hello';
$comment->save();
有人能解释一下为什么 CodeIgniter 会这样建模并让我感觉更好吗? (或者告诉我我能做些什么来解决它。)
【问题讨论】:
-
我不知道他们为什么会这样设计,但是你可以通过使用 Datamapper ORM (datamapper.exitecms.org) 来实现你想要的,它是专门为 Codeigniter 构建的最受欢迎的 ORM。
-
@bobo 嘿,如果你想回答我会接受的。其他答案很有帮助,但我最终选择了 Datamapper。谢谢。
标签: php model-view-controller codeigniter model