创建类以反映我的数据库模型

时间:2011-02-06 15:07:43

标签: php object object-relationships

我正在尝试在php中编写我的第一个面向对象的项目,我之前已经完成了oop但是它已经有一段时间了,而且它不是带有数据库模型的web dev,所以它有点不同而且我是在创建课程时遇到了麻烦。

无论如何,我的问题是我有这个对象,我们称之为x,x有一个所有者,y,所以我在x里面有一个类人的实例,而所有者y有一个帐户,z。

这样一切正常,我可以访问x的所有者信息,并且所有者帐户信息也可以。

但我需要双向工作,我需要能够查找帐户,然后找到拥有该帐户及其所有x的人。

cakephp可以处理这些关系但我找不到任何关于如何自己编写这种系统的指南。

感谢。

2 个答案:

答案 0 :(得分:0)

也许这个链接可以帮到你。

http://www.packtpub.com/article/working-with-simple-associations-using-cakephp

似乎有一些例子。

答案 1 :(得分:0)

Zend Framework支持模型关系,其文档也是quite extensive

典型情景:

$table = new Owner_Table();
$owner = $table->find(123); // owner id, many more sophisticated fetching methods are available
$account = $owner->findDependentRowset('account')->current(); // fetches records from the other table according to the relationship definition in the table object