Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: tpl -> podmiana styli
Forum PHP.pl > Forum > Przedszkole
Daimos
witam, mam taka klase:
  1. <?php
  2.  
  3. class Template {
  4.  
  5. var $strTemplateDir = './templates/testowy';
  6. var $strBeginTag = '{';
  7. var $strEndTag = '}';
  8. var $arrVars = array();
  9. var $arrValues  = array();
  10.  
  11. function assign( $strVar, $strValue ) {
  12. $this->arrVars[]  = $this->strBeginTag . $strVar . $this->strEndTag;
  13. $this->arrValues[] = $strValue;
  14. }
  15.  
  16. function display( $strFile ) {
  17. $resFile = fopen( $this->strTemplateDir . '/' . $strFile, 'r' );
  18. $strBuff = fread( $resFile, filesize( $this->strTemplateDir . '/' . $strFile ) );
  19. $strTest = str_replace( $this->arrVars, $this->arrValues, $strBuff );
  20. echo $strTest;
  21. }
  22. }
  23. ?>


wszystko dziala ok, ale chce zrobic mozliwosc podmiany templetow, i jak zrobie cos takiego:
  1. <?php
  2.  
  3. $wybranystyl = &#092;"testowy\";
  4. class Template {
  5.  
  6. var $strTemplateDir = './templates/'.$wybranystyl; // tu jest cos nie tak
  7. var $strBeginTag = '{';
  8. var $strEndTag = '}';
  9. var $arrVars = array();
  10. var $arrValues  = array();
  11.  
  12. function assign( $strVar, $strValue ) {
  13. $this->arrVars[]  = $this->strBeginTag . $strVar . $this->strEndTag;
  14. $this->arrValues[] = $strValue;
  15. }
  16.  
  17. function display( $strFile ) {
  18. $resFile = fopen( $this->strTemplateDir . '/' . $strFile, 'r' );
  19. $strBuff = fread( $resFile, filesize( $this->strTemplateDir . '/' . $strFile ) );
  20. $strTest = str_replace( $this->arrVars, $this->arrValues, $strBuff );
  21. echo $strTest;
  22. }
  23. }
  24. ?>

to wywala bledy :/
dr_bonzo
Cytat
// tu jest cos nie tak

Po prostu swietny opis bledu!

Pamietaj o zakresie widocznosci zmiennych:
  1. <?php
  2. class Template {
  3. global $wybranystyl;
  4. var $strTemplateDir = './templates/'.$wybranystyl; // tu jest cos nie tak
  5. ?>


ale to jest bardzo syfiarskie rozwiazanie.

  1. <?php
  2. var $strTemplateDir = './templates/';
  3. function Teplate( $template_dir )
  4. {
  5. $this->strTemplateDir .= $template_dir;
  6. ...
  7. }
  8.  
  9. ?>
Daimos
dalej mam problem ;(
bo chce pobrac z pliku tekstowego wybrany styl, robie tak:

  1. <?php
  2. $wybrany = file_get_contents(&#092;"wybrany.txt\");
  3.  
  4. $wybrany = file_get_contents(&#092;"wybrany.txt\");
  5. class Template {
  6.  
  7. global $wybrany;
  8. var $strTemplateDir = './templates/'.$wybrany;
  9. var $strBeginTag = '{';
  10. var $strEndTag = '}';
  11. var $arrVars = array();
  12.  
  13.  
  14.  
  15. ?>
i dalej wywala blad
w ten sposob rownierz blad:
  1. <?php
  2. class Template {
  3. var $wybrany = file_get_contents(&#092;"wybrany.txt\");
  4. global $wybrany;
  5. var $strTemplateDir = './templates/'.$wybrany;
  6. var $strBeginTag = '{';
  7. ?>



juz doszedlem, zrobilem jak napisales nizej:
  1. <?php
  2. var $strTemplateDir = './templates/';
  3. function Teplate( $template_dir )
  4. {
  5. $this->strTemplateDir .= $template_dir;
  6. ...
  7. }
  8.  
  9. ?>
dzieki
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.