Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> parser Szablonów
dez17
post 22.06.2005, 15:34:02
Post #1





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 22.06.2005

Ostrzeżenie: (0%)
-----


Na początku witam wszystkich.
A teraz problem.
Czytałem ten artykuł
http://php.org.pl/artykuly/3/16
i nie moge sobie poradzić z utworzeniem pliku templates.php stale jakiś błąd mi wyskakuje. Może ktoś mi go napisać poprawnie. A o to co mi wyszło:
php:

  1. <?php
  2. /******************************************************************************
  3. *  miniTemplate v. 1.2
  4. * Prosta klasa obsługi szablonów oparta na wzorze Splatch'a (splatch@wp.pl)
  5. ******************************************************************************/
  6.  
  7. class template
  8. {
  9. var $template = array();
  10. var $files = array();
  11.  
  12. function template($dir)
  13. {
  14. if($dir == &#092;"\")
  15. {
  16. $this -> set_root(&#092;"\");
  17. }
  18. else
  19. {
  20. $this -> set_root($dir);
  21. }
  22. return true;
  23. }
  24. function set_root($dir)
  25. {
  26. if($dir != &#092;"\")
  27. {
  28. if(!is_dir($dir))
  29. {
  30. die(&#092;"Template: nie mozna znalesc sciezki do szablonu.\");
  31. }
  32. else
  33. {
  34. $this -> root = $dir;
  35. }
  36. }
  37.  }
  38.  function set_files($files)
  39. {
  40. if(!is_array($files))
  41. {
  42. die(&#092;"Template: funkcja set_files przyjmuje tylko tablice!\");
  43. }
  44. else
  45. {
  46. while(list($tpl_id,$file) = @each($files))
  47. {
  48. $this -> files[$tpl_id] = $this -> root .&#092;"\". $file;
  49.  
  50. }
  51. }
  52. }
  53.  
  54. function assign_vars($tpl_id,$values)
  55. {
  56. if(!is_array($values))
  57. {
  58. die(&#092;"Template: funkcja assign_vars() przyjmuje wartsci tylko w tablicy.\");
  59. }
  60. else
  61. {
  62. reset($values);
  63. while(list($tag,$value) = @each($values))
  64.  {
  65. $this -> template[$tpl_id][tag][$tag] = $value;
  66.  }
  67. }
  68. return true;
  69. }
  70.  
  71.  function assign_var($tpl_id,$tag, $value)
  72. {
  73. if(empty($tag))
  74. {
  75.  die(&#092;"Template: w funkcji assign_var() musisz podac nazwe znacznika!\");
  76. }
  77. $this -> template[$tpl_id][tag][$tag] = $value;
  78. return true;
  79. }
  80.  
  81. function clear($tpl_id)
  82. {
  83. unset($this -> template[$tpl_id]);
  84. unset($this -> template[$tpl_id][tag]);
  85. unset($this -> template[$tpl_id][tag][]);
  86. }
  87.  
  88.  function compile($tpl_id,$code)
  89. {
  90.  while(list($key, $value) = @each($this -> template[$tpl_id][tag]))
  91. {
  92.  $tag = '{'.$key.'}';
  93.  if(!strstr($code, $tag))
  94.  {
  95. die(&#092;"Template: nie mozna znalesc znacznika $tag w pliku\");
  96.  }
  97.  $code = str_replace($tag, $value, $code);
  98. }
  99. return $code;
  100. }
  101.  
  102.  function pparse($tpl_id)
  103. {
  104. if(empty($this -> files[$tpl_id]))
  105. {
  106.  die(&#092;"Template: tablica <i>files</i> dla wartosci <i>$tpl_id</i> jest pusta.\");
  107. }
  108. $file = $this -> files[$tpl_id];
  109. $code = @implode(&#092;"n\",@file($file));
  110. $gcode = $this-> compile($tpl_id,$code);
  111. $gcode = str_replace(&#092;"nn\", $gcode);
  112. return($gcode);
  113. }
  114.  function parse($tpl_id)
  115. {
  116. print($this -> pparse($tpl_id));
  117. }
  118.  
  119. }
  120. ?>




I pokazuje mi ,że z linijką
php:

Kod
unset($this -> template[$tpl_id][tag][]);
(linijka 87)

Coś jest nie tak tylko co Question Prosze o pomoc albo napisanie tego pliku z góry thx

Ten post edytował dez17 22.06.2005, 15:34:32
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 18.07.2025 - 14:55