Hi,
I am building a CMS for a photo gallery. For this I have several classes, such as:
Artist
Album
Gallery
Photo
The way it works is, an Artist can have multiple Albums. An Album can have galleries, and a gallery photos. Each of these has a different file for its class, but they all use the Photo class...
Is there an easy way to access the photo class from within another class? And without re-declaring the Photo var's from within the Gallery or Album class?
This is a simplified version of what I have:
class Gallery {
var $gallery_name;
var $photo_id;
var $photo_name;
function Gallery($id) {
// Get all gallery details from DB
if (!($result=mysql_db_query(DB, "SELECT * FROM gallery WHERE gallery_id='$id'"))) {
ErrorMessage(sprintf("error getting all galleries %d:%s\n", mysql_errno(), mysql_error()));
exit();
}
$row=mysql_fetch_array($result);
$this->gallery_name=$row["gallery_name"];
// Get Photos for this Gallery, from PHOTO class
include_once("classes/class_photo.php");
if (!is_object($photo_class)) {
$photo_class = new Photo($id);
}
// so, this gets all photos for this gallery... but then I have to declare:
$this->photo_id=$photo_class["photo_id"];
$this->photo_name=$photo_class["photo_name"];
// ...etc, as the var's aren't declared
}
}
Note that I have to declare the photo vars in this class to get it to work, and assign them a value from the photo_class vars... there must be a better way to do this as some of my classes have heaps of vars.
Thanks,
Yari