by zemaj · 16y ago · 0 comments
There's definitely a need for a 'great' PHP ORM. I've been rolling my own for a couple of years since I've never been satisfied with what's out there. Here's the kind of syntax/style I use on mine (that class definition is the entire code I need to write to get working abstraction).
class Person extends Model {
const TABLE_NAME = 'people';
const TABLE_KEY = 'id';
}
$person = Model::find("Person", 1234);
$person->name = "James";
$person->save();
$persons_named_james = Model::find("Person", array("name" => "James"));
foreach($persons_named_james as $person) {
print $person->age;
}
$person = new Person();
$person->age = 26;
$person->save();
I should really upgrade to 5.3 so I could write Person::find(1234); instead.
hello
world
http://news.ycombinator.com/formatdoc (this used to be in a help link next to the reply box, but seems to be gone now).There are pieces to dislike (arguably DQL, soft deletes are almost impossible, etc) but so far, it's a huge step forward from the likes of Zend_Db_Table or Doctrine 1.
http://www.doctrine-project.org/projects/orm/2.0/docs/refere...
http://www.php.net/manual/en/function.get-called-class.php#9...
syntas like $peopleNamedJames = Doctrine::getTAble("Person")->findByName("James"); foreach( $peopleNamedJames as $person ){ echo $person->getAge(); }
It's very Hibernate'esqe in some regards also.