Object Oriented Programming Problem
- by Danny Love
I'm designing a little CMS using PHP whilst putting OOP into practice. I've hit a problem though.
I have a page class, whos constructor accepts a UID and a slug. This is then used to set the properties (unless the page don't exist in which case it would fail). Anyway, I wanted to implement a function to create a page, and I thought ... what's the best way to do this without overloading the constructor. What would the correct way, or more conventional method, of doing this be?
My code is below:
<?php
class Page {
private $dbc;
private $title;
private $description;
private $image;
private $tags;
private $owner;
private $timestamp;
private $views;
public function __construct($uid, $slug) {
}
public function getTitle() {
return $this->title;
}
public function getDescription() {
if($this->description != NULL) {
return $this->description;
} else {
return false;
}
}
public function getImage() {
if($this->image != NULL) {
return $this->image;
} else {
return false;
}
}
public function getTags() {
if($this->tags != NULL) {
return $this->tags;
} else {
return false;
}
}
public function getOwner() {
return $this->owner;
}
public function getTimestamp() {
return $this->timestamp;
}
public function getViews() {
return $this->views;
}
public function createPage() {
// Stuck?
}
}