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 parameters 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?
+1
A:
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;
}
}
Petah
2010-10-20 14:10:25
A:
Are you asking how to store associations? If so:
http://articles.sitepoint.com/article/hierarchical-data-database
Andrew Sledge
2010-10-20 14:14:10