使用PHP构建ORM时需要哪些功能? [英] Features needed when building a ORM with PHP?

查看:55
本文介绍了使用PHP构建ORM时需要哪些功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从来没有真正欣赏过ORM,所以我认为解决此问题的唯一方法是自己建立一个基本的,这样我就可以看到所有的胡言乱语.因此,考虑到这一点,制作半可用的ORM需要包括哪些基本功能?

I have never really appreciated ORM's so I think that the only way to remedy this is to build a basic one myself so I can see what all the hubbub is. So with that in mind, what are the basic features I would need to include to make a semi-usable ORM?

据我所知,对于最终程序员,它基本上需要像这样工作:

As far as I can tell, it would basically need to work like this for the end programmer:

/*
 * Create a user
 */
$user = new User();
$user->name = 'Joe';
$user->email = 'joe@aol.com';
$user->save();
unset($user);

/*
 * Create a game
 */
$game = new Game();
$game->name = 'soccer';
$game->save();

/*
 * Set all users as players
 */
$users = ORM::factory('users');
$users = $users->findAll();
foreach ( $users as $user ) {
    $user->setGame($game);
    $user->save();
}
unset($users);

/*
 * Get all games and show all users
 */
$games = ORM::factory('games')->findAll();
foreach( $games as $game ) {
    print $game->name;
    print 'Users in game:';
    foreach( $game->users as $user ) {
        print $user->name;
    }
}

每个模型类都将扩展具有所有基本方法的ORM类

Each model class would extend the ORM class which would have all the basic methods

  • 查找($ id)
  • findAll($ where)
  • 保存()

其他有用的功能可能是:

Other usefull features would be things like:

  • 能够请求具有特定ID User::find(34)的行
  • 能够使用类似WHERE的选项来限制结果行
  • 能够将一个行对象绑定到另一张表中的许多行. (1对很多)
  • 构建查询,以便自动编写SQL.
  • Able to request rows with a certain id User::find(34)
  • Able to limit result rows with WHERE like options
  • Able to tie one row object to many rows from another table. (1 to many)
  • Query building so that the SQL was written automatically.

其他人能告诉我我需要什么吗?我一直在查看一些库,例如 Doctrine dORM KohanaPHP ,但我似乎找不到易于理解的库以找出功能清单需要解决这个项目.

Could anyone else tell me what I would need. I've been looking at some of the libraries like Doctrine, EZPDO, dORM, and KohanaPHP but I can't seem to find a library that is easy to digest to figure out what the feature list would need to be to tackle this project.

我找到了图像详细信息一些ruby的产品以及有关 IgnitedRecord 项目.

I found an image detailing some of ruby's offerings and some more info on the IgnitedRecord Project.

推荐答案

以下是ORM应该具有的基本功能和扩展功能的列表: http://madgeek.com/Articles/ORMapping/EN/mapping.htm

Here is a list of basic and extended features ORM is supposed to have: http://madgeek.com/Articles/ORMapping/EN/mapping.htm

这篇关于使用PHP构建ORM时需要哪些功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆