Heeej,

Ik had gister een idee om (ik denk) snel websites te kunnen maken. Hier is de download link : download

De index.php ziet er als volgt uit:

<?php
include_once("lib/Website.class.php");
include_once("lib/Position.class.php");
include_once("lib/Module.class.php");
include_once("lib/Database.class.php");

//MODULES
include_once("modules/Tekst.php");
include_once("modules/Menu.php");
include_once("modules/LoginForm.php");

//MAAK VERVINDING MET EEN DATABASE
Database::Connect("localhost","root","","social");

//START WEBSITE
$website = new Website('Dennis Sluijk - Home');
$website->addStylesheet('style/style.css');
$website->addJavascript('lib/javascript/jquery.js');
$website->addJavascript('lib/javascript/dynaload.js');

//MAKE MENU
$mainmenu = new Menu();

$home = new MenuItem('Home','index.php','');

$informatie = new MenuItem('Informatie','informatie.php','');

$informatiesub = new Menu();
$informatiesub->addMenuItem(new MenuItem('Honden','#',""));
$informatiesub->addMenuItem(new MenuItem('Katten','#',""));

$informatie->addMenu($informatiesub);

$mainmenu->addMenuItem($home);
$mainmenu->addMenuItem($informatie);

//MAKE LOGIN FORM
$loginform = new LoginForm();

$left = new Position('left');
$left->appendModule($mainmenu);
$left->appendModule($loginform);

$tekst = new Tekst('Test test TEKST TEKST IPSUM DINGEN');

$content = new Position('content');
$content->appendModule($tekst);

$main = new Position('main');
$main->appendPosition($left);
$main->appendPosition($content);

//APPEND POSITIONS
$website->appendPosition($main);


echo $website->fetch();

?>

Je kan natuurlijk het menu enzovoorts opslaan in een appart bestand die je dan bij de volgende pagina bijvoorbeeld cats.php alleen hoef te includen. Het uiteindelijke doel van het systeem is zodat je dingen kan hergebruiken

hier is een download link voor alle bestanden: download

Mij vraag is wat jullie er van vinden
heb je ergens een voorbeeld online staan?
Nee. Ik heb geen hostingplekje
Wat is hiervan het voordeel ten opzichte van views? (met een parser zoals smarty)
Jah zat er al aan te denken om een soort fileInclude functie te maken waar je dan gewoon een file kan opgeven. en dat je dan gewoon data kan meesturen
<?php

class Template
{
public $vars;
public $file;

function __construct($file = null)
{
$this->file = $file;
}

function set($name,$value)
{
$this->vars[$name] = is_object($value) ? $value->fetch() : $value;
}

function fetch($file = null)
{
if(!$file) $file = $this->file;
if($this->vars) extract($this->vars);

ob_start();
include($file);
$content = ob_get_contents();

ob_end_clean();

return $content;
}
}

?>

Dit is het zelfde idee als smarty..
En wat word hier het voordeel van, bovenop smarty?
Nee, dit is geen smarty, omdat hier geen gebruik wordt gemaakt van een externe template.

Elke klasse vertegenwoordigt een HTML element..

OT: Het ziet er goed uit. Lijkt een beetje op de java.awt klassen bibliotheek.
Als een functie zo begint:
function fetch($file = null)
neem ik aan dat er een extern bestand in word geladen.
Deze Template class is toch bijna het zelfde idee als Smarty ?? of heb ik dat nou fout??? Dit is een uitbreiding van de Template classe

<?php
class CachedTemplate extends Template
{
public $expireTime;

public $cached_id;

public $cached;

public function __construct($cached_id = null, $expireTime = 600) {
$this->expireTime = $expireTime;

$this->cached_id = 'cache/' . md5($cached_id);
}

public function is_cached() {

if($this->cached) return true;

if(!$this->cached_id) return false;

if(!file_exists($this->cached_id)) return false;

if(!($fmtime = filemtime($this->cached_id))) return false;

if(($fmtime + $this->expireTime) < time()) {
@unlink($this->cache_id);
return false;
}
else {
$this->cached = true;

return true;
}
}

public function fetch_cache($file) {
if($this->is_cached()) {
$filehandle = fopen($this->cached_id, 'r');
$data = fread($filehandle, filesize($this->cached_id));
fclose($filehandle);

return $data;
}
else {
$data = parent::fetch($file);

$filehandle = fopen($this->cached_id, 'w');
fwrite($filehandle, $data);
fclose($filehandle);

return $data;
}
}

public function dump() {
if($this->is_cached()) {
@unlink($this->cache_id);
}
}


}

?>

hiermee kan je templates mee cachen

Reageren