Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: System szablonow (klasy)
Forum PHP.pl > Forum > Przedszkole
Gość_bim
Pisze system szablonow w klasie, i mm problemik. Nie za bardzo rozumiem jak napisac systethemow w klasie. Mialem kiedys na funkcjach ale to przestazale. Daje sobie jako tpl i w nim jest no
<table><tr><td>{top}</td></tr></table>
a klase mam:
  1. <?php
  2. class theme {
  3. var $top;
  4. function theme($top) {
  5. $this->top=$top;
  6. }
  7. function load() {
  8. global $theme, $folder, $adres, $nazwa;
  9.  
  10. $theme = file_get_contents( 'theme/default/default.tpl' );
  11.  $theme = ereg_replace( '{title}', $nazwa, $theme );
  12.  
  13. $theme = ereg_replace( '{lewe}', 'lewe', $theme );
  14. $theme = ereg_replace( '{top}', $this->top, $theme );
  15.  $theme = ereg_replace( '{prawe}', 'right', $theme );
  16.  $theme = ereg_replace( '{adres}', $adres, $theme );
  17. $theme = ereg_replace( '{folder}', $folder, $theme );
  18. //$theme= ereg_replace( '{blok_usera}', blok_user(), $theme );
  19. echo $theme;
  20.  
  21.  
  22. }
  23. }
  24. ?>
A wywoluje :
  1. <?
  2. if( !@include("config.php") )  
  3. die("<b>Brak pliku config.php</b>"); 
  4.  
  5.  
  6. $thm= new theme(top());
  7. $thm->load();
  8. function top() {
  9. global $link, $db, $config, $page, $prefix, $autorzy, $folder, $autorzy_ava, $zap, $adres, $folder, $mail, $REMOTE_ADDR;
  10.  
  11. if( !include('mody/'.$link[0].'.php') )  
  12. die("<b>Nie ma takiego modułu. Błąd!!!</b>"); 
  13. }
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20. ?>
Help me sadsmiley02.gif
Gość_bim
a problem jest taki ze jak wywoalam
$thm= new theme('hello');
$thm->load();

To sie wyswietli w dobrym miejscu, a jak dam kod php np. jakies zapytania itp. to na samej gorze sie wyswietla :/ Jak sparsowac zeby kod sie wykonal i to co wyrzuci sie wyswietlilo? dry.gif
AxZx
nie mozesz dac echo w funkcji bo wtedy bedzie wywalac na gorze,
daj return tego tekstu ktory chcesz wyswietlic z funkcji.\
Gość_bim
nadal jest na gorze (wczesniej dalem return i zmienilem na echo z mysal ze zadziala :?. Macie pomysly? sadsmiley02.gif
Guest
wiem co jest zle a nie wiem jak naprawic :/
  1. class theme {
  2. var $top;
  3. var $theme;
  4. var $plik;
  5. function theme($plik) {
  6.  
  7.  if(file_exists($plik)){
  8. $f = fopen($plik, 'r');
  9. $this -> theme = fread($f, filesize($plik));
  10. fclose($f);
  11.  }else{ echo 'Blad wczytania templatki'; }
  12. }
  13. function load($top) {
  14. global $theme, $folder, $adres, $nazwa;
  15. $this->top=$top;
  16.  
  17.  $this->theme = ereg_replace( '{title}', $nazwa, $this->theme );
  18.  
  19. $this->theme = str_replace( '{lewe}', 'lewe', $this->theme );
  20. $this->theme = str_replace( '{top}', $this->top, $this->theme );
  21.  $this->theme = str_replace( '{prawe}', 'right', $this->theme );
  22.  $this->theme = str_replace( '{adres}', $adres.'/', $this->theme );
  23. $this->theme = str_replace( '{folder}', $folder, $this->theme );
  24. //$theme= ereg_replace( '{blok_usera}', blok_user(), $theme );
  25. $theme='?>'.$this->theme.'<?';
  26. echo eval($theme);
  27.  
  28.  
  29. }
  30. }
,_moja klasa ale jak mam plik:
  1. <?php
  2. $page=$link[1];
  3.  $lim = $config['news_limit'];
  4. $sql = "SELECT COUNT(*) FROM {$prefix}news WHERE jaki='1' ORDER BY id";
  5. $ile = $db->result($db->query($sql),0);
  6. $limit = $page * $lim;
  7. $sa = "SELECT * FROM {$prefix}news WHERE jaki='1' ORDER BY id DESC LIMIT $limit, $lim";
  8. $result = $db->query($sa);
  9. $il = $db->num_rows($result);
  10.  
  11.  
  12. $query1 = "SELECT * FROM {$prefix}sources";
  13. $result1 = $db->query($query1);
  14. while($r3 = $db->fetch_array($result1)) {
  15.  
  16. $source[$r3['id']]='<a href="'.$r3['linka'].'" target="_blank">'.$r3['linkb'].'</a>';
  17.  
  18. }
  19.  
  20. while($r = $db->fetch_array($result)) {
  21.  
  22.  
  23.  
  24.  
  25. $text = make_clickable($r['text']);
  26. $text = bbcode($text, 1);
  27. $text = smilies($text);
  28. $data_format = date($config[data], $r['date']);
  29.  
  30. if($source[$r['source']]!='') {
  31. $sources='Żródło: '.$source[$r['source']];
  32. } else { $sources=''; }
  33.  
  34. news($r['author'], $data_format, $sources, $text, $r['id'], $r['comm'], $r['title']);
  35.  
  36.  
  37. }
  38. echo '<div class="tekst">Strony:<br>';
  39. $row = (int) $ile;
  40. $ile = $ile / $lim;
  41. $ile = ceil($ile);
  42. if($page==''){$page=0;}
  43. if($ile<>'1'){
  44. $odnosnik = '';
  45. if($page>'0'){echo '[<a href="'.$odnosnik.''.($page-1).'">poprzednia</a>]';}
  46. if($page>='4'){echo '[<a href="'.$odnosnik.'0">1</a>]...';}
  47. if($page>'2'){echo '[<a href="'.$odnosnik.''.($page-3).'">'.($page-2).'</a>]';}
  48. if($page>'1'){echo '[<a href="'.$odnosnik.''.($page-2).'">'.($page-1).'</a>]';}
  49. if($page>'0'){echo '[<a href="'.$odnosnik.''.($page-1).'">'.$page.'</a>]';}
  50. echo '[<font color="red"><b>'.($page+1).'</b></font>]';
  51. if($page<($ile-1)){echo '[<a href="'.$odnosnik.''.($page+1).'">'.($page+2).'</a>]';}
  52. if($page<($ile-2)){echo '[<a href="'.$odnosnik.''.($page+2).'">'.($page+3).'</a>]';}
  53. if($page<($ile-3)){echo '[<a href="'.$odnosnik.''.($page+3).'">'.($page+4).'</a>]';}
  54. if($page<($ile-4)){echo '...[<a href="'.$odnosnik.''.($ile-1).'">'.$ile.'</a>]';}
  55. if($page<($ile-1)){echo '[<a href="'.$odnosnik.''.($page+1).'">nastepna</a>]';}
  56. }else{echo '[<b>1</b>]';}
  57. echo '</div></br></font>';
  58.  
  59. ?>
to usuwa wszytskie przed i z $db-> :/ macie pomysly?
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.