Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: systemik szabloników
Forum PHP.pl > Forum > Przedszkole
Hpsi
Moj problem polega na tym, że:
mam se plik skorka.php w nim klasa skorka, w niej znajdują sie metody jak poniżej. no i tam sobie pliczek index.php gdzie testuje dzialanie klasy a w nim takie cos:
  1. <?php
  2.  
  3. require_once('skorka.php');
  4. $skorka = new skorka('1'); // 1 to nazwa skorki z kotrej ma pobierac informacje.
  5. $skorka->mn_open(); 
  6. echo '1 '; // echowanie tytulu ( {tytul} )
  7. $skorka->mn_close();
  8. echo '2'; // echowanie tresco ( {textl} )
  9. $skorka->mt_close();
  10.  
  11. ?>


No i mam takie metody w klasie:

  1. <?php
  2. function mn_open() 
  3. {
  4.  global $tpl;
  5. $tp_tmp['main'] = array();
  6. } 
  7.  
  8. function mn_close() {
  9.  global $tp_tmp;
  10.  $tpl['main']['title'] = ob_get_contents();
  11. } 
  12. function mt_close() {
  13.  global $tpl;
  14.  $tpl['main']['text'] = ob_get_contents();
  15.  $tpl_file = file_get_contents('theme/'.$this->theme.'/tpl/main.tpl');
  16.  
  17.  $main = str_replace('{tytul}', $tpl['main']['title'], $tpl_file);
  18. $main = str_replace('{text}', $tpl['main']['text'], $main);
  19. return $main;
  20.  
  21. } 
  22.  
  23. ?>


ponado maly pliczek z "szablonkiem":
Kod
{tytul}<br/>
<hr>
{text}


I co mi wyswietla ? tylko "2" co tutaj skonciłem. Proszę nie polecać smartów gdyż w tym projekcjie nie moge ich użyc ... niestety ... z góry dzieki za pomoc
nospor
Rzucilo mi sie w oczy dwie rzeczy:
1) funkcja mn_open() - robisz global $tpl u używasz $tp_tmp
2) funckcja mn_close() - robisz global $tp_tmp a używasz $tpl
Hpsi
blach moj bład, bo zmienialem kilkukrnie bo myslalem ze zmienne sie gryzly, no ale.
ale i tak nadal to nie działa :/

-- zapodac cała klase ?
nospor
zapodaj. powiedz również jakiego efektu oczekujesz (co ma się wyświetlać)
Hpsi
sorki ze dopiero teraz ale poszedłem sie zdrzemnac po całonej pracy biggrin.gif
  1. <?php
  2.  class skorka
  3.  {
  4.      var $theme;
  5.          function skorka($theme)
  6.          {
  7.              
  8.              $this->theme = $theme;
  9.          }    
  10.              
  11.          
  12.          function tpl($string, $file)
  13.          {
  14.              
  15.              $string = str_replace('{theme}', $this->theme, $string);
  16.              if($file != '')
  17.              {
  18.                  $bbmls = $GLOBALS['bbmls'];
  19.                  $bbmls->use_file($file);     
  20.                  $string = preg_replace('{[([^:}]+):([^}]+)]}e', '$bbmls->fetch('__1_2')', $string);                
  21.              }
  22.              
  23.              
  24.          }
  25.              function menu($r)
  26.              {
  27.                      $string = file_get_contents('theme/'.$this->theme.'/tpl/menu.tpl');        
  28.                      $string = str_replace('{tytul}', $r['tytul'], $string);
  29.                      $string = str_replace('{tresc}',  eval('?>'.$r['tresc'].'<?php'), $string);
  30.                      return $string;
  31.                          
  32.              }                             
  33.              
  34.                  function news($r, $kom)
  35.                  {
  36.                      $bbmls = $GLOBALS['bbmls'];
  37.                      $bbat = $GLOBALS['bbat'];
  38.                      $bbmls->use_file('news');
  39.                      $string = file_get_contents('theme/'.$this->theme.'/tpl/news.tpl');        
  40.                      $string = str_replace('{tytul}', $r['tytul'], $string);
  41.                      $string = str_replace('{tresc}',  nl2br($r['tresc']), $string);
  42.                      if($r['dtresc'] == '') {$string = str_replace('{wiecej}', '', $string);} else { $string = str_replace('{wiecej}',  '<a href=\"'.$bbat->make_link('nowosci', $r['id']).'\">'.$bbmls->fetch('__news_wiecej').' ', $string); } 
  43.                      if($bbat->get(1) == '') {$string = str_replace('{dluga:tresc}', '', $string);} else { $string = str_replace('{dluga:tresc}', nl2br($r['dtresc']), $string); }
  44.                      if($bbat->get(1) == '') {$string = str_replace('{wstecz}', '', $string);} else { $string = str_replace('{wstecz}', '<a href=\"javascript.go(-1)\">'.$bbmls->fetch('__news_wstecz').'', $string); } 
  45.                      $string = str_replace('{komentarze}', '<a href=\"'.$bbat->make_link('komenarze', 'nowosci', $id).'\">'.$bbmls->fetch('__news_komenatrze').'('.$kom.')', $string);
  46.                     return $string;                     
  47.                  }
  48.                           function mn_open() {
  49.                              global $tpl;
  50.                               ob_start();
  51.                              $tpl['main'] = array();
  52.                             
  53.                         } 
  54.                         
  55.                         function mn_close() {
  56.                              global $tpl;
  57.                              $tpl['main']['title'] = ob_get_contents();
  58.                              ob_end_clean();
  59.                                                         
  60.                         } 
  61.                         
  62.                         
  63.                         function mt_close() {
  64.                              global $tpl;
  65.                               ob_start();
  66.                              $tpl['main']['text'] = ob_get_contents();
  67.                              ob_end_clean();
  68.                          
  69.                                  $tpl_file = file_get_contents('theme/'.$this->theme.'/tpl/main.tpl');
  70.                              
  71.                                  $main = str_replace('{tytul}', $tpl['main']['title'], $tpl_file);
  72.                                  $main = str_replace('{text}', $tpl['main']['text'], $main);
  73.                                  return skorka::tpl($main, '');
  74.                                                     
  75.                         } 
  76.                                                      
  77.  }
  78. ?>

Oczekuje efektu ze zrobi mi cos takiego ze w main.tpl bede mial wyglad zwyklego działu, a w kodzie mam cos takiego
  • mam coś takiego $skorka->mn_open(); echo tytul; $skorka->mn_close(); chce zeby to co pomedzy mn_open i close zostało przezuczone do talicy $tpl['main']['title']
  • nastepnie mam pomedzy mn_close() a mt_close(); echo tresc; chce zeby to wrzucilo do tablicy $tpl['main']['title'];
  • nastpenie chce aby mn_close(); mi przefiltrowało wszystko, do pliczku mani.tpl i wyrzucilo zawartośc tpl z odpowienimi modenizacjami. w tablach chce przechowywac kod html, php itd ..
Błąd znaleźiony smile.gif
w ob_start() pokreciłem. dzięki za pomoc nospor winksmiley.jpg
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.