Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: system szablonow] wlasny
Forum PHP.pl > Forum > PHP
Dex1987
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...
  1. <?php
  2.  
  3. class templates {
  4.  
  5. var $template_name;
  6. var $template_content;
  7.  
  8. var $varible;
  9. var $section;
  10.  
  11. var $templates_dir = "templates";
  12. var $cache_dir  = "cache/templates";
  13.  
  14. function assign ($varible_name, $varible_value) {
  15.  
  16.  $this -> varible[$varible_name] = $varible_value;
  17.  $this -> section[$varible_name] = $varible_value;
  18. }
  19.  
  20. function display ($template_name) {
  21.  
  22.  $this -> template_name  = $template_name;
  23.  $this -> template_content = "<?php /* File compiled from '" .$this -> template_name. "' to '" .$this -> template_name. ".php' on (date) */ ?>nn";
  24.  
  25.  if (!@implode ("", file ($this -> templates_dir. "/" .$this -> template_name))) {
  26.  
  27.  echo "<font face='verdana' size='1'>Nie można otworzyc pliku <b>" .$this -> template_name. "</b>.<br></font>";
  28.  
  29.  } else {
  30.  
  31.  $this -> template_content .= @implode ("", file ($this -> templates_dir. "/" .$this -> template_name));
  32.  }
  33.  
  34.  if (preg_match ('/{$([a-zA-Z0-9_]+)}/', $this -> template_content)) {
  35.  
  36.  $this -> template_content = preg_replace ('/{$([a-zA-Z0-9_]+)}/', '<?php echo $this -> varible['$1']; ?>', $this -> template_content);
  37.  }
  38. /*
  39.  if (preg_match ('/{section[$([a-zA-Z0-9_]+)]}/', $this -> template_content)) {
  40.  
  41.  $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);
  42.  }
  43. */
  44.  if (preg_match ('/{section[$([a-zA-Z0-9_]+)]}/', $this -> template_content)) {
  45.  
  46.  $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);
  47.  }
  48.  
  49. /*
  50.  if (preg_match ('/{section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+)}/', $this -> template_content)) {
  51.  
  52.  $this -> template_content = preg_replace ('/{section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+)}/', '<?php echo $row[$this -> section['$1']]['$2']; ?>', $this -> template_content);
  53.  }
  54. */
  55.  if (preg_match ('/{section[$([a-zA-Z0-9_]+)].([a-zA-Z0-9_]+)}/', $this -> template_content)) {
  56.  
  57.  $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);
  58.  }
  59.  
  60.  if (preg_match ('/{/section}/', $this -> template_content)) {
  61.  
  62.  $this -> template_content = preg_replace ('/{/section}/', '<?php } ?>', $this -> template_content);
  63.  }
  64.  
  65.  if (preg_match ('/{iteration[$([a-zA-Z0-9_]+)]}/', $this -> template_content)) {
  66.  
  67.  $this -> template_content = preg_replace ('/{iteration[$([a-zA-Z0-9_]+)]}/', '<?php echo $this -> section['$1']['start']+1; ?>', $this -> template_content);
  68.  }
  69.  
  70.  if (preg_match ('/{include=$([a-zA-Z0-9_]+)}/', $this -> template_content)) {
  71.  
  72.  $this -> template_content = preg_replace ('/{include=$([a-zA-Z0-9_]+)}/', '<?php include ($this -> varible['$1']); ?>', $this -> template_content);
  73.  }
  74.  
  75.  if (!$file_open = @fopen ($this -> cache_dir. "/" .$this -> template_name. ".php", 'w')) {
  76.  
  77.  echo "<font face='verdana' size='1'>Nie można utworzyć pliku wykonywalnego dla systemu szablonów: <b>" .$this -> template_name. ".php</b>.<br></font>";
  78.  }
  79.  
  80.  if (!@fputs ($file_open, $this -> template_content)) {
  81.  
  82.  echo "<font face='verdana' size='1'>Błąd zapisu do pliku: <b>" .$this -> template_name. "</b>.<br></font>";
  83.  }
  84.  
  85.  if (!@fclose ($file_open)) {
  86.  
  87.  echo "<font face='verdana' size='1'>Błąd przy zamykaniu pliku: <b>" .$this -> template_name. "</b>.<br></font>";
  88.  }
  89.  
  90.  if (!@include ($this -> cache_dir. "/" .$this -> template_name. ".php")) {
  91.  
  92.  echo "<font face='verdana' size='1'>Błąd dołączenia sparsowanego pliku: <b>" .$this -> template_name. "</b>.<br></font>";
  93.  }
  94. }
  95. }
  96.  
  97. ?>


To jest troche chaotycznie pisane wiec nie patrzcie na kod.

  1. {section[$dane]}
  2.  
  3. pole z bazy: {section[$dane].nazwa_pola_z_bazy}
  4.  
  5. {/section}


Uzycie klasy tak jak w smarty smile.gif. Podobna systuacja jest w smarty. Tez cos takiego nie dziala albo nie wiem jak zrobic. Piszcie swoje pomysly na rozwiazanie tego problemu.
aleksander
Systemy szablonów => php
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.