Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][SMARTY] dziedziczenie?
Forum PHP.pl > Forum > Przedszkole
Gryf
Witam przeglądam forum i niestety nie znalazłem rozwiązania problemu.
Mam klasę a która to dziedziczy po klasie smarty i w niej ustawiam sobie
wszystkie pathe, casching, debuging itd...
teraz chciałem aby klasa b dziedziczyła od klasy a jej funkcjonalność i mieć możliwość
dodania do niej kolejnych funkcji tyle że dostaje błąd
Warning: Smarty error: unable to read resource: "a.tpl" in C:\...\Smarty.class.php on line 1092

  1. <?php
  2. class a extends Smarty
  3. {
  4. public function __construct()
  5. {
  6. $this -> Smarty();
  7. $this -> template_dir = '../templates/';
  8. $this -> compile_dir = '../templates_c/';
  9. $this -> config_dir  = '../configs/';
  10. $this -> cache_dir = '../cache/';
  11. $this -> compile_check = true;
  12. $this -> debugging = true;
  13. $this -> force_compile = true;
  14. $this -> caching = 0;
  15. }
  16. }
  17.  
  18. class b extends a
  19. {
  20. public function __construct() {
  21. echo 'dziedzicze i...';
  22. }
  23. public function __destruct() {
  24. }
  25. }
  26. ?>

kiedy operuje na samej klasie a wszystko działa ale gdy b to dostaje ten błąd.
nospor
zapomniales wywolac w b konstruktor a
  1. <?php
  2. class b extends a
  3. {
  4. public function __construct() {
  5. echo 'dziedzicze i...';
  6. parent::__construct();
  7. }
  8. }
  9. ?>
JoShiMa
Cytat(Gryf @ 14.08.2008, 13:20:57 ) *
dodania do niej kolejnych funkcji tyle że dostaje błąd
Warning: Smarty error: unable to read resource: "a.tpl" in C:\...\Smarty.class.php on line 1092

A klasa potomna jest w tym samym katalogu co rodzic? Bo to wygląda na jakiś błąd w ścieżkach dostępu w wyniku którego szuka a.tpl a miejscu w którym go nie ma.
nospor
@JoShiMa chodzi oto, co napisalem, czyli ze nie wywolal konstruktora rodzica, w ktorym to ustawial wlasciwe sciezki.
Heweliusz
Masz po prostu błędną ścieżkę do folderu z szablonami.
Spórbuj tak:
  1. <?php
  2. class a extends Smarty
  3. {
  4. public function __construct()
  5. {
  6. $this -> Smarty();
  7. $root_path = getcwd() . '/';
  8. $this -> template_dir = $root_path . 'templates';
  9. $this -> compile_dir = $root_path . 'templates_c';
  10. $this -> config_dir  = $root_path . 'configs';
  11. $this -> cache_dir = $root_path . 'cache';
  12. $this -> compile_check = true;
  13. $this -> debugging = true;
  14. $this -> force_compile = true;
  15. $this -> caching = 0;
  16. }
  17. }
  18. ?>
nospor
o rety....
czytajcie co napisal autor:
Cytat
kiedy operuje na samej klasie a wszystko działa ale gdy b to dostaje ten błąd.

Samo A dziala. Nie dziala B bo nie dal konstruktora z A, w ktorym to wszystko ustawia !
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.