开发者

implementation of relations between classes in oop php

I am new in PHP with classes. I am coding an network ip-mac-user logging system integrated with dhcp. I have users, subnets, units. I created classes for each and created parameters and functions to fill the paramete开发者_开发知识库rs and some mysql codes about what they do. but there are relationships among these classes. where can I put these relations' codes, functions, for example there are m-n relations between subnets and units, where should I put the relationship codes?


In the class that relates to the other class. Just make sure you don't have circular references or you will run into memory trouble.

class Adult {
    private $children = false;
    public function get_children() {
        // This is where you get the related instances
        if ($this->children === false) {
            $this->children = db_fetch('children', $this->get_id()); 
        }
        return $this->children;
    }
}


Are you asking how to store associations? If so:

http://articles.sitepoint.com/article/hierarchical-data-database

http://en.wikipedia.org/wiki/Associative_Entities

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜