Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Odnoszenie się do instancji obiektu w includowanym pliku
kyez
post 2.01.2015, 20:39:29
Post #1





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 6.09.2011

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


Witajcie,

mam taki problem, jest sobie plik index.php w którym tworzę sobie obiekt $db i na nim wykonuję opercje bazodanowe.
zaraz pod nim includowany jest plik header.php w którym jest odwołanie do obiektu $db, no i to niestety nie trybi.

index.php
  1. <?php
  2. require_once "../init.php";
  3. require_once "../core/config.php";
  4.  
  5. $modules = new modules();
  6. $db = new db($configs['db_user'], $configs['db_pass'], $configs['db_server'], $configs['db_name']);
  7.  
  8. $modules->getHeader();
  9. $modules->getAdminHeader();
  10. $offers = $db->getAllOffers();
  11.  
  12. ?>



header.php
  1. <meta charset="UTF-8">
  2. <title><?php $db->getTitle();?></title>
  3. <link rel="stylesheet" type="text/css" href="">
  4. <script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
  5. <!-- Latest compiled and minified CSS -->
  6. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
  7. <link rel="stylesheet" href="../css/dashboard.css">
  8. <!-- Optional theme -->
  9. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css">
  10.  
  11. <!-- Latest compiled and minified JavaScript -->
  12. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
  13.  
  14. function toggle(obj, e)
  15. {
  16. var elems = e.split(",");
  17. for(i=0;elems[i];i++)
  18. document.getElementById(elems[i]).style.display = (obj.checked==true)? 'block':'none';
  19. }
  20. </script>
  21.  
  22.  
  23. </head>
  24.  
  25.  


Dzięki i pozdrawiam.

Ten post edytował kyez 2.01.2015, 20:42:26
Go to the top of the page
+Quote Post
Forti
post 2.01.2015, 20:46:14
Post #2





Grupa: Zarejestrowani
Postów: 655
Pomógł: 73
Dołączył: 2.05.2014

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


1. Dostajesz jakiś błąd?
2. co znaczy nie trybi?
3. Włącz raportowanie błędów
4. na pewno include robisz pod tym?


--------------------
Overwatch24 - najbardziej zaawansowany Polski portal Overwatch od fanów dla fanów.

Fachowo.co

Behance.net/fachowo
Go to the top of the page
+Quote Post
sazian
post 2.01.2015, 20:46:25
Post #3





Grupa: Zarejestrowani
Postów: 1 045
Pomógł: 141
Dołączył: 19.09.2006
Skąd: B-tów

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


a gdzie ten include headera ?
a zresztą mniejsza
daj w headerze var_dump($db); i zobacz co tam siedzi
Go to the top of the page
+Quote Post
SpiritCode
post 2.01.2015, 20:57:47
Post #4





Grupa: Zarejestrowani
Postów: 167
Pomógł: 35
Dołączył: 29.12.2014
Skąd: Otwock

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


Niby w ciemno ale... Jeśli chodzi o ten title to nie musisz dać tam echo?
  1. <?php echo $db->getTitle()?>

Go to the top of the page
+Quote Post
kyez
post 2.01.2015, 21:00:08
Post #5





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 6.09.2011

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


Fatal error</b>: Call to a member function getTitle() on a non-object in..
includuje w pliku modeules.php

  1. class modules
  2. {
  3.  
  4. public function getHeader($type = FALSE)
  5. {
  6. if(isset($type) and $type == 'admin')
  7. {
  8. if(file_exists("../modules/headeradmin.php"))
  9. {
  10. include_once "../modules/headeradmin.php";
  11. }
  12. else
  13. {
  14. include_once "modules/headeradmin.php";
  15. }
  16. }
  17. else
  18. {
  19. if(file_exists("../modules/header.php"))
  20. {
  21. include_once "../modules/header.php";
  22.  
  23. }
  24. else
  25. {
  26. include_once "modules/header.php";
  27. }
  28. }
  29. }
  30.  
  31. public function getAdminHeader($type = FALSE)
  32. {
  33. if(file_exists("../modules/adminHeader.php"))
  34. {
  35. include_once "../modules/adminHeader.php";
  36. }
  37. else
  38. {
  39. include_once "modules/adminHeader.php";
  40. }
  41.  
  42. }
  43.  
  44.  
  45. }
Go to the top of the page
+Quote Post
sazian
post 2.01.2015, 21:15:43
Post #6





Grupa: Zarejestrowani
Postów: 1 045
Pomógł: 141
Dołączył: 19.09.2006
Skąd: B-tów

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


zasięg zmiennych kolego
wewnątrz klasy nie masz dostępu do zmiennych z zewnątrz
Go to the top of the page
+Quote Post
kyez
post 4.01.2015, 17:30:15
Post #7





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 6.09.2011

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


Jakaś propozycja jak to rozwiązać? Głowię się i nie mogę wpaść ;/
Go to the top of the page
+Quote Post
sazian
post 5.01.2015, 20:21:21
Post #8





Grupa: Zarejestrowani
Postów: 1 045
Pomógł: 141
Dołączył: 19.09.2006
Skąd: B-tów

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


  1. class modules
  2. {
  3. private $db;
  4. public function setDb($db)
  5. {
  6. $this->db=$db;
  7. }
  8. }
  9. $db = new db($configs['db_user'], $configs['db_pass'], $configs['db_server'], $configs['db_name']);
  10. $modules = new modules();
  11. $modules->setDb($db);
  12.  

header.php
  1.  
  2. <title><?php $this->db->getTitle();?></title>
Go to the top of the page
+Quote Post
kyez
post 5.01.2015, 23:13:42
Post #9





Grupa: Zarejestrowani
Postów: 48
Pomógł: 0
Dołączył: 6.09.2011

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


Dzieki serdecznie !

Można zamknąć smile.gif
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 Wersja Lo-Fi Aktualny czas: 22.06.2025 - 04:35