推荐一个短小精悍的ActiveRecord库,lloydzhou/activerecord · GitHub, 可以实现类似Yii的relation的效果。文档地址:http://lloydzhou.github.io/activerecord/
class User extends ActiveRecord{ public $table = ‘user‘; public $primaryKey = ‘id‘; public $relations = array( ‘contacts‘ => array(self::HAS_MANY, ‘Contact‘, ‘user_id‘) ); } class Contact extends ActiveRecord{ }
$user = new User(); // find one user var_dump($user->notnull(‘id‘)->orderby(‘id desc‘)->find()); echo "\nContact of User # {$user->id}\n"; // get contacts by using relation: // ‘contacts‘ => array(self::HAS_MANY, ‘Contact‘, ‘user_id‘), var_dump($user->contacts);
原文:http://www.cnblogs.com/lloydzhou/p/4836743.html