Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> jak zrobic z tego tablice, $tpl->assign( 'cos', $coss);
Daimos
post
Post #1





Grupa: Zarejestrowani
Postów: 1 319
Pomógł: 118
Dołączył: 26.11.2003
Skąd: Lublin

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


Witam, mam klase do templatów:
  1. <?php
  2. class Template {
  3. var $strTemplateDir = './layouty/';
  4. var $strBeginTag = '{';
  5. var $strEndTag = '}';
  6. var $arrVars = array();
  7. var $arrValues  = array();
  8.  
  9. function Teplate( $template_dir )
  10. {
  11. $this->strTemplateDir .= $template_dir;
  12. }
  13.  
  14. function assign( $strVar, $strValue ) {
  15. $this->arrVars[]  = $this->strBeginTag . $strVar . $this->strEndTag;
  16. $this->arrValues[] = $strValue;
  17. }
  18.  
  19. function display( $strFile ) {
  20. $strFile = $strFile.'.tpl';
  21. $resFile = fopen( $this->strTemplateDir . '/' . $strFile, 'r' );
  22. $strBuff = fread( $resFile, filesize( $this->strTemplateDir . '/' . $strFile ) );
  23. $strTest = str_replace( $this->arrVars, $this->arrValues, $strBuff );
  24. echo $strTest;
  25. }
  26. }
  27. ?>


uzywam tego w ten sposob:
  1. <?php
  2. $tpl = new template;
  3. $tpl->Teplate( $wybrany );
  4. $tpl->assign( 'cos', $jakaszmienna);
  5. $tpl->assign( 'cos2', '<b>jakis kod html');
  6. $tpl->display( 'index' ); 
  7. ?>


Wszystko dziala ladnie pieknie, ale widzialem kiedys w skrypcie phpbb ze tak jak wyzej mam "assign" bylo w tablicy... chcialbym to samo osiagnac tylko niewiem jak
Dokladnie chodzi mi o taki efekt:

  1. <?php
  2. $tpl = new template;
  3. $tpl->Teplate( $wybrany );
  4. $tpl->assign( 
  5. 'cos' = $jakaszmienna,
  6. 'cos2' = '<b>jakis kod html',
  7.  
  8. // i tak dalej, po prostu wygodniej :) pomoze ktos ? (IMG:http://forum.php.pl/style_emoticons/default/snitch.gif)
  9. );
  10. $tpl->display( 'index' ); 
  11. ?>
Go to the top of the page
+Quote Post
NuLL
post
Post #2





Grupa: Zarejestrowani
Postów: 2 262
Pomógł: 21
Dołączył: 3.05.2004
Skąd: Sopot, Krakow, W-wa

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


Z takim prościutkim parserem szablonów raczej tego nie osiagniesz...
Go to the top of the page
+Quote Post
hwao
post
Post #3


Developer


Grupa: Moderatorzy
Postów: 2 844
Pomógł: 20
Dołączył: 25.11.2003
Skąd: Olkusz




Da sie zrobic funckje ze zmienna iloscia parametrow... poczytaj o tym w manualu (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) moze ich byc nawet 50000 (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg) skrypt sam je wykryje.

Ale o ile dobrze pamietam (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif) (po 3 dniach nie spania;) ) to taki zapis nie przejdzie $cos = 'costam' musial bys tam dawac tablice.... array( 'cos' => 'costam' ), array( 'c' => $z ) ale wtedy to to traci sens przeciez bo lepiej dac 1 tablice.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 28.09.2025 - 13:41