Przekazywanie zapytań między plikami

0

Cześć,
a początk może pokażę błąd jaki otrzymuję:

Fatal error: Using $this when not in object context in C:\WebServ\httpd\oop_mvc\model\Forum\Stats.class.php on line 5
Teraz kod:

Plik Stats.class.php(Model):

<?php
class DownStatistics extends Database{
   static public function Stats() {
	  $user_unactive = $this->getPdo()->prepare("SELECT `aktywny` FROM `users` LIMIT 1");
	if (!$user_unactive->execute()){
		 print_r($user_unactive->errorInfo());
	}
}
?>

Plik IndexForum.phtml(View):

<?php
   $db = new Database();
   $db->connect();
   DownStatistics::Stats();
?>

Plik Forum.php(Controller):

<?php 

require_once("../../controller/ConfigDatabase.class.php");
require_once("../../model/Forum/GetPlayerStatistics.class.php"); 
require_once("../../view/IndexForum.phtml"); 

?>

Z bazą łączę się się poprawnie. I tak jak pisałem wcześniej, błąd to:

Fatal error: Using $this when not in object context in C:\WebServ\httpd\oop_mvc\model\Forum\Stats.class.php on line 5

Odnosi się on do zapytania. Co jest nie tak?

0

Ta funkcja w której wyskakuje błąd to funkcja statyczna, nie możesz w niej odwoływać się do instancji klasy.

0

Lecz gdy funkcja nie jest statyczna wyskakują 2 błędy:

Strict Standards: Non-static method DownStatistics::GetPlayerStatistics() should not be called statically in C:\WebServ\httpd\oop_mvc\view\IndexForum.phtml on line 58

Fatal error: Using $this when not in object context in C:\WebServ\httpd\oop_mvc\model\Forum\GetPlayerStatistics.class.php on line 5

Zatem nie wiem co zrobić.

1

Przede wszystkim pomyśleć. Albo chcesz mieć funkcję statyczną i wywoływać ją statycznie (Klasa::funkcja()) albo nie-statyczną, wtedy masz dostęp do $this i wywoływać ją via $instancja->funkcja().

1 użytkowników online, w tym zalogowanych: 0, gości: 1