Witam, pisze system szablonow. ale napotkalem na pewien blad. Jak mam np petle w mysql_fetch_array to wszystko pieknie wyswietla ale jak chce dodac do tego zapytanie z where to sie juz wszystko rozwala.
Parser...
<?php
class templates {
var $template_name;
var $template_content;
var $varible;
var $section;
var $templates_dir = "templates";
var $cache_dir = "cache/templates";
function assign ($varible_name, $varible_value) {
$this -> varible[$varible_name] = $varible_value;
$this -> section[$varible_name] = $varible_value;
}
function display ($template_name) {
$this -> template_name = $template_name;
$this -> template_content = "<?php /* File compiled from '" .$this -> template_name. "' to '" .$this -> template_name. ".php' on (date) */ ?>nn";
if (!@implode ("", file ($this -> templates_dir
. "/" .$this -> template_name
))) {
echo "<font face='verdana' size='1'>Nie można otworzyc pliku <b>" .$this -> template_name
. "</b>.<br></font>";
} else {
$this -> template_content
.= @implode ("", file ($this -> templates_dir
. "/" .$this -> template_name
)); }
if (preg_match ('/{$([a-zA-Z0-9_]+)}/', $this -> template_content
)) {
$this -> template_content
= preg_replace ('/{$([a-zA-Z0-9_]+)}/', '<?php echo $this -> varible['$
1']; ?>', $this -> template_content
); }
/*
if (preg_match ('/{section[$([a-zA-Z0-9_]+)]}/', $this -> template_content)) {
$this -> template_content = preg_replace ('/{section[$([a-zA-Z0-9_]+)]}/', '<?php while ($row[$this -> section['$1']] = mysql_fetch_array ($this -> section['$1'])) { ?>', $this -> template_content);
}
*/
if (preg_match ('/{section[$([a-zA-Z0-9_]+)]}/', $this -> template_content
)) {
$this -> template_content
= preg_replace ('/{section[$([a-zA-Z0-9_]+)]}/', '<?php for ($this -> section['$
1']['start
'] = 0; $this -> section['$
1']['start
'] <= count ($this -> section['$
1'])-2; $this -> section['$
1']['start
']++) { ?>', $this -> template_content
); }
/*
if (preg_match ('/{section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+)}/', $this -> template_content)) {
$this -> template_content = preg_replace ('/{section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+)}/', '<?php echo $row[$this -> section['$1']]['$2']; ?>', $this -> template_content);
}
*/
if (preg_match ('/{section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+)}/', $this -> template_content
)) {
$this -> template_content
= preg_replace ('/{section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+)}/', '<?php echo $this -> section['$
1'][$this -> section['$
1']['start
']]['$
2']; ?>', $this -> template_content
); }
if (preg_match ('/{/section}/', $this -> template_content
)) {
$this -> template_content
= preg_replace ('/{/section}/', '<?php } ?>', $this -> template_content
); }
if (preg_match ('/{iteration[$([a-zA-Z0-9_]+)]}/', $this -> template_content
)) {
$this -> template_content
= preg_replace ('/{iteration[$([a-zA-Z0-9_]+)]}/', '<?php echo $this -> section['$
1']['start
']+1; ?>', $this -> template_content
); }
if (preg_match ('/{include=$([a-zA-Z0-9_]+)}/', $this -> template_content
)) {
$this -> template_content
= preg_replace ('/{include=$([a-zA-Z0-9_]+)}/', '<?php include ($this -> varible['$
1']); ?>', $this -> template_content
); }
if (!$file_open = @fopen ($this -> cache_dir
. "/" .$this -> template_name
. ".php", 'w')) {
echo "<font face='verdana' size='1'>Nie można utworzyć pliku wykonywalnego dla systemu szablonów: <b>" .$this -> template_name
. ".php</b>.<br></font>"; }
if (!@fputs ($file_open, $this -> template_content
)) {
echo "<font face='verdana' size='1'>Błąd zapisu do pliku: <b>" .$this -> template_name
. "</b>.<br></font>"; }
echo "<font face='verdana' size='1'>Błąd przy zamykaniu pliku: <b>" .$this -> template_name
. "</b>.<br></font>"; }
if (!@include ($this -> cache_dir. "/" .$this -> template_name. ".php")) {
echo "<font face='verdana' size='1'>Błąd dołączenia sparsowanego pliku: <b>" .$this -> template_name
. "</b>.<br></font>"; }
}
}
?>
To jest troche chaotycznie pisane wiec nie patrzcie na kod.
{section[$dane]}
pole z bazy: {section[$dane].nazwa_pola_z_bazy}
{/section}
Uzycie klasy tak jak w smarty

. Podobna systuacja jest w smarty. Tez cos takiego nie dziala albo nie wiem jak zrobic. Piszcie swoje pomysly na rozwiazanie tego problemu.