Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Problem z funkcją set_template
Yazzie
post
Post #1





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 5.04.2007
Skąd: Otwock

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


Witam

Oto moje pliki:

class/template_class.php
  1. <?php
  2. class template
  3. {
  4. var $theme = 'Default';
  5. var $assigned_vars = array();
  6. var $template_content = '';
  7. var $block_vars = array();
  8. var $template_html = NULL;
  9.  
  10. function add_file ($template_file)
  11. {
  12. $template_path = "./templates/$this->theme/$template_file";
  13.  
  14. if (file_exists($template_path))
  15. {
  16. $this->template_content = file_get_contents($template_path);
  17. }
  18. else
  19. {
  20. echo ("[ <b>Template</b> ] :: Szablon $template_path nie może zostać odnaleziony<br>");
  21. }
  22. }
  23.  
  24. function set_block_template ($block_name, $array)
  25. {
  26. if ( is_array($array) )
  27. {
  28. $temp_array = array();
  29. $block_count = 0;
  30.  
  31. foreach ($array as $key => $value)
  32. {
  33. $temp_array[$key] = $value;
  34. $block_count++;
  35. }
  36. $this->block_name[$block_name][] = $temp_array;
  37. }
  38. else
  39. {
  40. echo ("[ <b>Template</b> ] :: Dane przekazane funkcją <b>assign_block</b> nie są tablicą");
  41. }
  42. }
  43.  
  44. function set_template ($array)
  45. {
  46. foreach ($array as $key => $value)
  47. {
  48. $this->assigned_vars[strtoupper($key)] = $value;
  49. }
  50.  
  51. foreach ($this->assigned_vars as $key => $value)
  52. {
  53. $this->assigned_vars = str_replace('{'.$key.'}', $value, $this->assigned_vars);
  54. }
  55.  
  56. echo $this->template_content;
  57. }
  58. ?>


index.php

  1. <?php
  2. $template = new template;
  3.  
  4. $template-> add_file("header.tpl");
  5. $template-> add_file("index.tpl");
  6. $template-> add_file("footer.tpl");
  7.  
  8. $user['lang'] = 'polish';
  9.  
  10. include ($keybb_path . "language/" . $user['lang'] . ".php");
  11.  
  12. $template-> set_template(array(
  13. "L_POWERED_INFO" => $lang['powered_info'],
  14. "ALL_POSTS" => $result_1,
  15. ));
  16. ?>


header.tpl

  1. <title>{BOARD_TITLE} - ( {L_POWERED_INFO} )</title>
  2. </head>
  3.  
  4. </body>
  5. </html>


Zamiast napisu {L_POWERED_INFO} powinno pojawiać się na stronie Strona oparta o skrypt, jednak tak się nie dzieje. Próbuję to rozgryźć kilka dni i nadal nic sad.gif

Pomocy
Go to the top of the page
+Quote Post
Kicok
post
Post #2





Grupa: Zarejestrowani
Postów: 1 033
Pomógł: 125
Dołączył: 17.09.2005
Skąd: Żywiec

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


Cytat
  1. <?php
  2.  
  3. foreach ($this->assigned_vars as $key => $value)
  4. {
  5. $this->assigned_vars = str_replace('{'.$key.'}', $value, $this->assigned_vars);
  6. }
  7.  
  8. ?>


Na pewno masz tutaj zmieniać $this->assigned_vars? A nie czasem $this->template_content ? ;]


--------------------
"Sumienie mam czyste, bo nieużywane."
Go to the top of the page
+Quote Post
Yazzie
post
Post #3





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 5.04.2007
Skąd: Otwock

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


Dzięki, teraz działa, no głupi błąd, jak mogłem tego nie zauważyć biggrin.gif

Dzięki jeszcze raz tongue.gif

Okazuje się, że mam jeszcze jeden błąd. Nie wiem czemu, ale pokazuje tylko jeden plik template, choć w index.php są zakotwiczone 3. Co jest nie tak?
Go to the top of the page
+Quote Post
abc667
post
Post #4





Grupa: Zarejestrowani
Postów: 229
Pomógł: 0
Dołączył: 29.05.2007

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


  1. <?php
  2. $this->template_content .= file_get_contents($template_path);
  3. ?>


np. ?
Go to the top of the page
+Quote Post
Yazzie
post
Post #5





Grupa: Zarejestrowani
Postów: 37
Pomógł: 0
Dołączył: 5.04.2007
Skąd: Otwock

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


Dzięki, teraz wszystko pięknie gra, thx.
Go to the top of the page
+Quote Post

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 Aktualny czas: 21.08.2025 - 23:37