Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Klasa szablonów i include, Brak zmiennych?
Brand
post
Post #1





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 28.10.2009

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


Witam. Mam problem z moim skryptem. W szablonie nie widać zmiennych zadeklarowanych w klasie Index. Szablon jest wczytywany przez klasę Theme. Próbowałem ze zmiennymi globalnymi, ale to niestety nie pomaga. Czy jest jakieś rozwiązanie? Załączam uproszczoną wersję mojego skryptu. Pozdrawiam. (IMG:style_emoticons/default/smile.gif)

  1. <?php
  2. # index.php
  3. class Index
  4. {
  5. public function __construct()
  6. {
  7. $var = 'It works!';
  8. include('templates.class.php');
  9. $theme = new Theme;
  10. $theme -> load();
  11. }
  12. }
  13. new Index;
  14. ?>

  1. <?php
  2. # templates.class.php
  3. class Theme
  4. {
  5. public function load()
  6. {
  7. return include('szablon.php');
  8. }
  9. }
  10. ?>

  1. <?php
  2. # szablon.php
  3. echo 'theme included';
  4. echo '<br />';
  5. echo $var;
  6. ?>
Go to the top of the page
+Quote Post

Posty w temacie


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: 22.08.2025 - 14:11