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 man开发者_开发百科y peoples lives so much easier. Are there perhaps frameworks/ORM's that provide similar functionality etc?
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. :)
in CakePHP there are relationships such as hasMany, belongsTo, hasOne, and hasAndBelongsToMany
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).
精彩评论