Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z metodami Parenta
mkozak
post
Post #1





Grupa: Zarejestrowani
Postów: 78
Pomógł: 4
Dołączył: 21.03.2005

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


Są sobie 3 obiekty:

StdObj

Produkt

Produkt_extendent

dziedziczą jeden po drugim.

i teraz taka sytuacja - chcę zwrócić listę w pełni wypełnionych obektów z bazy

  1. <?php
  2. class Produkt extends StdObiekt{
  3. protected $produkt_id = -1;
  4. protected $produkt_nazwa = -1;
  5. protected $produkt_dostepnosc_id = -1;
  6. protected $produkt_typ_id = -1;
  7.  
  8. public function __construct($param = null){
  9. parent::__construct($param);
  10. }
  11.  
  12. public function __construct_from_assoc(array $t_prod){
  13. $this -> set('produkt_nazwa', $t_prod['produkt_nazwa']);
  14. $this -> set('produkt_data_dodania', $t_prod['produkt_data_dodania']);
  15. $this -> set('produkt_dostepnosc_id', $t_prod['produkt_dostepnosc_id']);
  16. }
  17.  
  18. public function dbPobierz($id = null){
  19.  
  20. if(isset($id)) $sql_id = 'WHERE produkt_id = ''.$id.''';
  21.  
  22. $sql = 'SELECT * FROM produkt '.$sql_id;
  23.  
  24. $t_produkt = getAssoc($sql);
  25.  
  26. $produkt = array_pop($t_produkt);
  27.  
  28. $this -> __construct_from_assoc($produkt);
  29.  
  30. return true;
  31. }
  32. }
  33.  
  34.  
  35. class Produkt_ext extends Produkt{
  36.  
  37. public $Produkt_ext_id = -1;
  38. public $Produkt_ext_nazwa = -1;
  39. public $Produkt_ext_opis = null;
  40. public $Produkt_ext_xml = null;
  41.  
  42. public $czy_jest_zestawem = 0;
  43. public $t_zestaw = array();
  44.  
  45. public function __construct($param = null){
  46. parent::__construct($param);
  47. }
  48.  
  49. public function __construct_from_assoc(array $t_param){
  50.  
  51. $this -> set('produkt_id', $t_param['produkt_id']);
  52.  
  53. $this -> set('Produkt_ext_id', $t_param['Produkt_ext_id']);
  54. $this -> set('Produkt_ext_nazwa', $t_param['Produkt_ext_nazwa']);
  55. $this -> set('Produkt_ext_opis', $t_param['Produkt_ext_opis']);
  56. $this -> set('Produkt_ext_xml', $t_param['Produkt_ext_xml']);
  57.  
  58. }
  59.  
  60. public function dbPobierz($id = null){
  61.  
  62. if(isset($id)) $sql_id = 'WHERE Produkt_ext_id = ''.$id.''';
  63.  
  64. $sql = 'SELECT * FROM Produkt_ext '.$sql_id;
  65.  
  66. $t_Produkt_ext = getAssoc($sql);
  67.  
  68. $Produkt_ext = array_pop($t_Produkt_ext);
  69.  
  70. $this -> __construct_from_assoc($Produkt_ext);
  71.  
  72. parent::dbPobierz($this->produkt_id);
  73.  
  74. if($this -> czy_jest_zestawem) $this -> pobierzElementyZestawu();
  75.  
  76. return true;
  77. }
  78. }
  79. ?>


no i jedziemy z koksem:

  1. <?php
  2. prod_ex = New Produkt_extendent();
  3.  
  4. prod_ex -> dbPobierz('1');
  5. ?>


No i jest dupa - bo w metodzie Produkt_ext -> dbPobierz() wywołuję parent::dbPobierz($this->produkt_id); a w dbPobierz() już nie wykonuje się __construct_from_assoc() z Produkt - tylko z Produkt_ext.

Nie mogę wrzucić do $Produkt->dbPobierz() zamiast $this -> __construct_from_assoc($produkt); dać parent no bo to nie logiczne i przestanie mi działać....

No any way.... to jakaś lipa....

W skrócie jeszcze raz

W poziomu Produkt_ext wywołuję parent::dbPobierz. W ciele klasy Produkt jest wywoływana metoda __construct_from_assoc (ale Produkt_ext też ma metodę __construct_from_assoc) no i wywołuje się ta z Produkt_ext a nie z Produkt.

Jakaś rada??


--------------------
==============================================
Bo ja jestem Wróbelek Htmlek
==============================================
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 Aktualny czas: 20.08.2025 - 18:16