Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Klasa, system styli
stroju
post 5.12.2008, 16:06:55
Post #1





Grupa: Zarejestrowani
Postów: 179
Pomógł: 2
Dołączył: 17.11.2005

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


mam taką klasę:
  1. <?php
  2. class temp
  3. {
  4.     var $file = '';
  5.    
  6.     function tpl_get_file($name)
  7.     {
  8.          global $config_ss, $root_path;
  9.          
  10.          $path = $root_path.'style/'.($config_ss['styl']).'/'.$name.'.html';
  11.          $this->file = file_get_contents($path);
  12.          return $this->file;
  13.     }
  14.    
  15.     function tpl_set_array($array)
  16.     {
  17.          foreach($array as $key => $war)
  18.          {
  19.               $this->files = str_replace('{'.$key.'}', $war, $this->file);
  20.          }
  21.          return $this->files;
  22.     }
  23.  
  24.  
  25.  
  26. }
  27. ?>


i kod który wyświetla mi plik:
  1. <?php
  2. $temp->tpl_get_file('show_profile');
  3.  
  4. echo $temp->tpl_set_array(array('STATUS' => 'dd',
  5. 'AVATAR' => 's'));
  6. ?>


i problem mam w tym że z tablicy $array w pliku podmieniana jest tylko ostatnia wartość, w tym wypadku 'AVATAR', choć jest tego więcej i tylko tę ostatnią zmienia...
w czym robię błąd??
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
JarCzeS
post 5.12.2008, 16:24:14
Post #2





Grupa: Zarejestrowani
Postów: 42
Pomógł: 0
Dołączył: 5.05.2008

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


  1. <?php
  2. function tpl_set_array($array)
  3.     {
  4.          foreach($array as $key => $war)
  5.          {
  6.               $this->files[] = str_replace('{'.$key.'}', $war, $this->file);
  7.          }
  8.          return $this->files;
  9.     }
  10. ?>

tpl_set_array nadpisuje caly czas wartosc zmiennej files, wyniki str_replace musisz do tablicy zapisywac i zwracac cala tablice

Ten post edytował JarCzeS 5.12.2008, 16:25:49
Go to the top of the page
+Quote Post
stroju
post 5.12.2008, 16:40:24
Post #3





Grupa: Zarejestrowani
Postów: 179
Pomógł: 2
Dołączył: 17.11.2005

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


no już mam, trochę inaczej ale mam rozwiązanie:
  1. <?php
  2. function tpl_set_array($array)
  3.     {
  4.          $this->files = $this->file;
  5.          foreach($array as $key => $war)
  6.          {
  7.               $this->files = str_replace('{'.$key.'}', $war, $this->files);
  8.          }
  9.          return $this->files;
  10.     }
  11. ?>


dzięki temu pracuje ciągle na jednej zmiennej, i w niej podmienia, bo w tablicy zwracałoby ciągle nową tabelkę, a tak ciągle pracuje na jednym pliku
Go to the top of the page
+Quote Post

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: 14.08.2025 - 03:10