Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> jak zrobic z tego tablice, $tpl->assign( 'cos', $coss);
Daimos
post 10.06.2005, 23:01:18
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 ? snitch.gif
  9. );
  10. $tpl->display( 'index' ); 
  11. ?>


--------------------
scriptun.com. Startup z poradnikami do gier ttp.zone i ttpzone.pl
Go to the top of the page
+Quote Post

Posty w temacie


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 - 09:28