PHP 中的 Ruby 风格关系表
我知道 ruby(在 Rails 上)使用了很多“魔法”,但我使用 PHP,是否没有一种方法可以实现类似 Rails 的功能:
class Player < ActiveRecord::Base
has_many :cards
end
在 PHP 中,它会让很多人的生活变得更加轻松。是否有框架/ORM 提供类似的功能等?
I know ruby (on rails) uses lots of "magic", but I use PHP, is there not a way of implementing the rails-like:
class Player < ActiveRecord::Base
has_many :cards
end
in PHP it would make so many peoples lives so much easier. Are there perhaps frameworks/ORM's that provide similar functionality etc?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您正在寻找的术语是“对象关系映射器”(ORM)。您引用的是 Rails 框架的一个组件,称为 ActiveRecord。
PHP ActiveRecord 是一个尝试提供此功能的项目,尽管最后一个版本是在 2010 年 7 月。我还没有实际使用过;我刚刚切换到 Rails。 :)
The term you're looking for is an "Object Relational Mapper" (ORM). The one you cite is a component of the Rails framework, called ActiveRecord.
PHP ActiveRecord is one project that attempts to provide this, though the last release was in July 2010. I haven't actually used it; I just switched to Rails. :)
在 CakePHP 有关系,例如 hasMany、belongsTo、hasOne、并且 hasAndBelongsToMany
in CakePHP there are relationships such as hasMany, belongsTo, hasOne, and hasAndBelongsToMany
PHP 本身没有 ORM,但是有几个相当有用的 ORM 项目;我熟悉 Propel,它相当好(例如在 Symfony 框架中使用,它有点类似于 Ruby) 。
PHP doesn't have a ORM by itself, but there are several fairly usable ORM projects for it; I'm acquainted with Propel, and it's rather good (used e.g. in the Symfony framework, which resembles Ruby somewhat).