Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Include - gubienir obiektu
xmarko
post 29.03.2009, 19:51:56
Post #1





Grupa: Zarejestrowani
Postów: 59
Pomógł: 0
Dołączył: 26.02.2004

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


Mam taki przykładowy error :
Fatal error: Call to a member function show() on a non-object in /var/www/html/dyplom/page/tresc1.php on line 2
Miałem nadzieję, że dołącze kod poprzez include i bede mógł korzystać z wcześniej zadeklarowanych obiektów. Jednak nie ma takiej możliwości obecnie, musze deklarować obiekt klasy PresentationClass w pliku tresc1.php od nowa. A ja chciałbym mieć możliwość dalej korzystać z obiektów, które powstają na poczatku. Nie chce tworzyc nowych. Prosze o pomoc w rozwiązaniu problemu.


Oto kod :
pik: test.php
  1. <?php
  2. require_once("class/PageClass1.php") ;
  3. require_once("class/PresentationClass.php") ;
  4. $Page = new  PageClass() ;
  5. $Pokaz = new PresentationClass() ;
  6.  
  7. $Page->addDiv("content","page/tresc1.php") ;
  8. $Page->show(); // pokaz zawartośc zbudowanego obiektu
  9.  
  10. ?>

plik : tresc1.php
  1. <?php
  2.  
  3. $Pokaz->show("wio");
  4. ?>

plik : PageClass1.php
  1. <?php
  2.  
  3. class PageClass {
  4.  
  5.         private $div = null ;
  6.  
  7.         function __construct() {
  8.  
  9.  
  10.         }
  11.  
  12.  
  13.         public function addDiv($styl,$plik=null) {
  14.                  if ($plik != null) {
  15.                           $this->div[] = array($styl=>$plik);
  16.                  }
  17.  
  18.         }
  19.  
  20.         public function showStruktura() {
  21.                        if ($this->div != null) {
  22.                           $w=null;
  23.                           $i=0;
  24.                           $d = count($this->div);
  25.                           while($i<$d) {
  26.                                    foreach ($this->div[$i] as $klucz=>$wartosc ){
  27.                                           print "<div id=\"".$klucz."\">\n";
  28.                                           include($wartosc) ;
  29.                                           print "</div>\n";
  30.                                   }
  31.                                    $i++;
  32.                           }
  33.  
  34.  
  35.                  }
  36.  
  37.  
  38.         }
  39.  
  40.  
  41.         // -------------------------------------------------------------------------------------- [ metody ]
  42.         public function show() {
  43.                  $part =  "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n" ;
  44.                  $part .="<html>\n" ;
  45.                  $part .="<head>\n" ;
  46.                print $part ;
  47.                  $this->showStruktura(); // podział strony w stylach
  48.  
  49.                  $part .= "</body>\n";
  50.                  $part .= "</html>\n";
  51.                  print $part; // wyswietlenie stony
  52.  
  53.         }
  54. }
  55. ?>

plik: PresentationClass.php
  1. <?php
  2. class PrezentationClass {
  3. // rózne zmienne i metody
  4. public function show($zm) {
  5. print $zm;
  6. }
  7. }
  8. ?>


Ten post edytował nospor 30.03.2009, 07:17:32


--------------------
marko
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: 24.07.2025 - 13:19