View previous topic :: View next topic
Author
Message
ToDD Joined: 05 May 2005 Posts: 83 Location: Zagreb
Posted: 09.12.2005 17:55 Post subject: klasa
imam ovu skriptu za template sistem
ali to je klasa pa me jebu malo varijable koje nisu u toj klasi
e sad kako bi to moglo bit napravljeno bez klase?
Code:
<?php
class Template
{
var $Template;
function Template($template) {
if (file_exists($template))
$this->Template = join("", file($template));
else
die('Izgled stranice '.$template.' nije naden.');
}
function parse($file) {
ob_start();
include($file);
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
function replace_tags($tags = array()) {
if (sizeof($tags) > 0)
foreach ($tags as $tag => $data) {
$data = (file_exists($data)) ? $this->parse($data) : $data;
$this->Template = eregi_replace("{" . $tag . "}", $data,
$this->Template);
}
else
die('Greška 90');
}
function ispisi() {
echo $this->Template;
}
}
$template_source = new Template('template/'.$_SESSION['template'].'/index.htm');
$template_source->replace_tags(array(
'naslov' => $naslov,
'glavno' => 'glavno.php',
'navigacija'=>'navigacija.php',
'impresum'=>'impresum.php',
'poruka'=>$poruka,
));
$template_source->ispisi();
?>
tu di je funkcija replace_tags tu ako se napise tekst onda ce npr {naslov} bit zamjenjen $naslov, a ako se upise file npr navigacija.php onda ce {navigacija} biti zamjenjena s sadrzajem filea navigacija.php
unaprijed hvala
Back to top
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
Powered by phpBB © 2001, 2005 phpBB Group