PHP Object to XML
Posted: Fri Nov 19, 2010 7:04 am
Hi,
I am currently building a very simple CMS. I am using OOP for generating static pages. However, I am having a problem with storing the objects. Can anyone suggest how can this be done by storing objects into XML files? I have heard of serialization but don't understand that approach completely.
//example of my class
class Page {
private $title;
private $heading;
private $content;
public function Page($t,$h,$c) {
$this->title = $t;
$this->heading = $h;
$this->content = $c;
}
public function getTitle() {
return $this->title;
}
public function getHeading() {
return $this->heading;
}
public function getContent() {
return $this->content;
}
}
//instantiating object
$title = $_POST['title'];
$heading = $_POST['heading'];
$content = $_POST['content'];
$myPage = new Page($title, $heading, $content);
//after this it should be stored as XML file, but don't know how
Thanx in advance.
I am currently building a very simple CMS. I am using OOP for generating static pages. However, I am having a problem with storing the objects. Can anyone suggest how can this be done by storing objects into XML files? I have heard of serialization but don't understand that approach completely.
//example of my class
class Page {
private $title;
private $heading;
private $content;
public function Page($t,$h,$c) {
$this->title = $t;
$this->heading = $h;
$this->content = $c;
}
public function getTitle() {
return $this->title;
}
public function getHeading() {
return $this->heading;
}
public function getContent() {
return $this->content;
}
}
//instantiating object
$title = $_POST['title'];
$heading = $_POST['heading'];
$content = $_POST['content'];
$myPage = new Page($title, $heading, $content);
//after this it should be stored as XML file, but don't know how
Thanx in advance.