Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Obsługa szablonów.
boosik01
post
Post #1





Grupa: Zarejestrowani
Postów: 91
Pomógł: 1
Dołączył: 19.08.2009

Ostrzeżenie: (10%)
X----


Cześć. Wziąłem się za pisanie systemu szablonów (nie mówić mi tu o Smarty bo i tak go nie użyję bo jest on jak dla mnie zbyt dużą aplikacją a po drugie do nauki postanowiłem napisać własny tongue.gif .)

Ok do rzeczy mam taki kod class.temp.php:

  1. <?php
  2. class new_template
  3. {
  4. private $sTemplate; // Szablon
  5. private $sReplacement; // Zamienniki
  6.  
  7. public function __construct($rFile_name, $z, $na)
  8. {
  9. $this->file_name = $rFile_name ;
  10. $this->template = $sTemplate ;
  11. $this->replacement = $sReplacement ;
  12. $this->z = $z ;
  13. $this->na = $na ;
  14. }
  15.  
  16. public function read()
  17. {
  18. if(!empty($this->file_name)) ;
  19. if(!file_exists($this->file_name))
  20. {
  21. trigger_error(' Błąd. Nie ma takiego pliku. ') ;
  22. return true ;
  23. }
  24.  
  25. $this->template = @file($this->file_name) ;
  26. $this->template = imlode("", $this->template);
  27. }
  28.  
  29. public function add_replacement()
  30. {
  31. if(!empty($this->z))
  32. {
  33. $this->replacement[$this->z] = $this->na ;
  34. }
  35. }
  36.  
  37. public function display()
  38. {
  39. $this->out = $this->templates ;
  40. foreach($this->replacement as $a => $b)
  41. {
  42. $this->out = str_replace("{$a}", $b, $this->out) ;
  43. }
  44.  
  45. return $this->out ;
  46. }
  47. }
  48.  
  49. ?>
  50.  


Oraz w index.php:

  1. $szab = new new_template('templates/index.tpl', '{a}', $cos) ;
  2. echo($szab->display());


I wywala mi błąd związany z pętlą for:

Kod
Warning: Invalid argument supplied for foreach() in C:\WebServ\httpd\gra-obiektowo\classes\temp.class.php on line 40
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 Aktualny czas: 22.08.2025 - 03:52