Chci se vyhrnout do jednoho "slozitejsiho" projektu v php.
Rozhod jsem se ze bych chtel tvorit layout podobne jako v Jave
(kdy do sebe vnoruju panely kterym priraruzju ruzny Layout managery.), jen trochu jednodussi(viz obrazek).
http://img174.imageshack.us/my.php?image=obrqp4.gif
Chtel bych to cely udelat v OOP. Napsal sem si par trid, ktery v podstate zatim nic neumej(vypisujou jen infa).
Je to jen navrh a propojeni jak by tvoreni layoutu melo v konecny fazy vypadat.
<?php
class Page {
public function __construct() {
echo "Class Page > New Page";
}
public function __destruct() {
echo "Class Page > Del instance of " .get_class()." class";
}
public function setPageTittle($tittle) {
echo "Class Page > set title to: ".$tittle."";
}
public function addSection($section) {
echo "Class Page > add new section ".$section->getId()."";
}
public function generate() {
}
}
class Section {
private static $no;
private $id;
public function __construct() {
self::$no++;
$this->id = self::$no;
echo "Class Section > New Section";
}
public function __destruct() {
$this->no--;
echo "Class Section > Del instance of " .get_class()." class";
}
public function getId() {
return $this->id;
}
public function setLayout(Layout $layout) {
}
}
abstract class Layout {
public function __construct() {
}
public function __destruct() {
}
abstract function makeLayout();
}
class threeLayout extends Layout {
public function __construct() {
echo "Class Layout > New ".get_class()."";
self::makeLayout();
}
public function __destruct() {
echo "Class Layout > Del instance of " .get_class()." class";
}
function makeLayout(){
echo "Class Layout > type: | a | b | c |";
}
}
class twoLayout extends Layout {
public function __construct() {
echo "Class Layout > New twoLayout";
self::makeLayout();
}
public function __destruct() {
echo "Class Layout > Del instance of " .get_class()." class";
}
function makeLayout() {
echo "Class Layout > type: | a | b |";
}
}
class cleanLayout extends Layout {
public function __construct() {
echo "Class Layout > New cleanLayout";
self::makeLayout();
}
public function __destruct() {
echo "Class Layout > Del instance of " .get_class()." class";
}
function makeLayout() {
echo "Class Layout > type: | a |";
}
}
?>
Layout by se tvoril tedy takto:
$page = new Page();
$page->setPageTittle("Titulek");
$section_1 = new Section();
$layout1 = new threeLayout(); //normalni instance
$section_1-> setLayout($layout1);
$page->addSection($section_1);
//podobne by se dal delal i obsah v samotnem layoutu
$section_2 = new Section();
$section_2-> setLayout(new twoLayout()); //anonymni instance
$page->addSection($section_2);
//podobne by se dal delal i obsah v samotnem layoutu
$page -> generate();
Problem ale je ten ze nevim jak nejak elegante implementovat tvoreni layoutu(generovani a vnorovani divu) v samotnych tridach ktere sem si napsal. Nevim jak to takhle v OOP realizovat. Takze bych potreboval od vas nejakou inspiraci...
PS: V PHP(zvlaste OOP) dost mizerny zkusenosti. Tak me za ten kod neukamenujte :)