PHP ActiveRecord(ORM) 库

推荐一个短小精悍的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);
posted @ 2015-09-24 22:11  lloydzhou  阅读(1425)  评论(0)    收藏  举报