<?php
namespace core;
use lib\Db;
class Model{
public $_attributes = [];
public $Db;
public function __construct($data = null) {
$this->_attributes = $data;
$this->Db = new Db;
print_r($this);
}
public function __get($name)
{
return $this->_attributes[$name];
}
public function __set($name, $value)
{
$this->_attributes[$name] = $value;
}
public function AuthCheck(){
if(!empty($_COOKIE['user'])){
$models = $this->LoadUser($_COOKIE['user']);
if(!empty($_COOKIE['user']) && !empty($_COOKIE['hash']) && $_COOKIE['hash'] == $models->access_token && $models->uid == $_COOKIE['user']){
return true;
}else
return false;
}else
return false;
}
public function LoadUser($uid){
print_r($this);
return $this->Db->fp("SELECT * FROM users WHERE uid = ?", [$uid]);
}
function loadUsersAll(){
return $this->Db->fALL("SELECT * FROM users");
}
}
Все находиться в одном файле но при вызове $this в функции объект Db пустой
lib\Db Object
(
[BDCONNECT:protected] => PDO Object
(
)
)
core\Model Object
(
[_attributes] =>
[Db] => lib\Db Object
(
[BDCONNECT:protected] => PDO Object
(
)
)
)
app\models\Model_Test Object
(
[_attributes] => Array
(
)
[Db] =>
)
Fatal error: Uncaught Error: Call to a member function fp() on null in /var/www/sogo.su/htdocs/core/Model.php:39
Stack trace:
#0 /var/www/sogo.su/htdocs/core/Model.php(28): core\Model->LoadUser('131721202')
#1 /var/www/sogo.su/htdocs/app/controller/TestController.php(17): core\Model->AuthCheck()
#2 /var/www/sogo.su/htdocs/core/Router.php(63): TestController->action_index()
#3 /var/www/sogo.su/htdocs/core/Router.php(24): core\Router::applyRoute(Array)
#4 /var/www/sogo.su/htdocs/index.php(13): core\Router::init()
#5 {main}
thrown in /var/www/sogo.su/htdocs/core/Model.php on line 39