在 FuelPHP 中使用模型?
我是 PHP 框架的新手,为了开始我的冒险,我尝试了 FuelPHP。经过几天的测试,我明白了事情是如何运作的。控制器控制操作,视图控制 $content,模板控制布局。但是模型呢?它们的用途是什么?
I'm new to PHP frameworks and to start my venture I went to try FuelPHP. After a few days of testing around I understood how things work. Controllers control the actions, views control the $content and the template controls the layout. But what about models, What are they for?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
模型是对存储在其他地方的数据的抽象,它们像普通对象一样通过标准对象创建、方法调用、属性访问等封装数据访问。这里的主要思想是控制器(或任何需要数据的对象)不需要知道如何获取数据或如何存储数据。它可以存储在文件、网络(通过网络服务)、数据库、任何可以保存数据的东西中。可以通过 Web 服务请求、数据库查询、文件读取等来检索数据。
例如,“给我 id 1 的学生记录”可以像
student := new Student(1);
一样简单,并且之后您就可以访问学生的姓名、地址等。但是学生如何检索其数据呢?它在哪里存储数据?这是出于关注,可以根据需要进行调整(或应该是可调整的)。Models are abstractions over data stored elsewhere, they encapsulate the data access through standard object creation, method calls, property access, etc. just like ordinary objects. The main idea here is that the controller (or whatever object that requires the data) doesn't need to know how to get the data or how it's stored. It could be stored in files, web (via webservice), database, whatever thing that could persist data. The data could be retrieved with webservice request, database query, file reading, etc.
For instance, "gimme student record with id 1" could be as simple as
student := new student(1);
and after that you have access to the student's name, address, etc. But how does the student retrieve its data? Where does it store the data? It's out of concern and could be tuned (or should be tunable) as needed.模型控制您的数据并与您的数据库直接联系,请阅读
models controle your data and have a direct contact with your db have a read here
您可能会说
“Contact With ID”、“Name”、“Detail”和“ContactType”属性。
这个想法是保持最小化,它基本上是一个实体的所有有用属性的集合。
这是 MVC 的当前定义。里面没有任何关于后端的内容。那将是一些单独的库/dll,它只知道模型以及底层数据如何存储在数据库中。
You might have say
Contact With ID,Name,Detail and ContactType properties.
The idea is to keep it minimal it's basically something to cart around all the useful properties of an entity.
This is the current definition of MVC. Nothing about the backend in it. That would be some seperate library / dll that only knows about model, and how the underlying data is stored in the DB.