对于日常网络开发使用的简单对象有什么想法吗?
天哪-我知道这是一个主观问题,所以可能会被启动/锁定,但无论如何我都会尝试,因为我不知道还能问哪里(请随时向我指出一个更好的地方来问这个问题!)
我只是用 PHP 来研究 oop,但我仍然没有使用框架或任何东西。
我想创建几个简单的小对象,可以在我自己的网站中使用它们,以便更好地了解它们。
谁能推荐一个列表或资源,让我说出人们会在基本网站中使用的 10 个日常对象?
我之所以问这个问题,是因为我自己有点困惑。例如,我正在考虑一个“数据库连接”对象,但后来我只是认为这只是一个函数,而不是真正的“对象”?
所以问题是:
基本 PHP 网站(不包括“购物车”类型网站)中使用的对象的一些示例有哪些?
谢谢!
Dang-I know this is a subjective question so will probably get booted off/locked, but I'll try anyway, because I don't know where else to ask (feel free to point me to a better place to ask this!)
I'm just wrapping my head around oop with PHP, but I'm still not using frameworks or anything.
I'd like to create several small simple objects that I could use in my own websites to better get a feel for them.
Can anyone recommend a list or a resource that could point me to say 10 day-to-day objects that people would use in basic websites?
The reason I'm asking is because I'm confusing myself a bit. For example, I was thinking of a "database connection" object, but then I'm just thinking that is just a function, and not really an "object"??
So the question is:
What are some examples of objects used in basic PHP websites (not including "shopping cart" type websites)
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
以下是您可能拥有的一些基本的可重用对象:
)听起来你想开始构建自己的 Web 框架,这是一种不错的学习方式。但不要重新发明轮子。对于生产站点,您可能最好使用现有框架。
Here's a few basic reusable objects you might have:
It sounds like you want to start to build your own web framework, which is a decent way to learn. Don't reinvent the wheel though. For a production site, you're probably better off using an existing framework.
既然您说过您不想再次粘合 HTML 和 CSS,那么您就不会尝试以下操作:
这些只是一些想法。有些事情可能没有意义:p
Since you said you don't want to glue HTML and CSS again, you don't try this:
These are just some ideas. Some things may not make sense :p
我想说数据库访问将是第一个最有可能的对象 - 将最常见的 SQL 请求封装到一个类中。如果您使它们足够抽象,您可以将它们用于各种数据访问情况。
考虑类设计/使用的方法是考虑类的责任。您应该能够用简短的句子(比这更短...)描述类的用途,即对于数据库访问对象,您可能会说:
“为常见数据访问任务提供API”
如果您的数据访问类中的任何方法做一些除此之外的事情,然后你就知道它们属于其他地方。
I'd say database access would be the first most likely object - encapsulate your most common SQL requests into one class. If you make them abstract enough, you can use them for a wide variety of data access situations.
The way to think about class design/usage is to think of the class responsibility. You should be able to describe the class purpose in a short sentence (shorter than this...) i.e for database access object, you might say:
"provides API for common data access tasks"
If any of the methods in your data access class do something other than that, then you know they belong somewhere else.