Bonjour, j'ai un soucis avec l'affichage de mon tableau :
Erreur afficher Fatal error: Call to a member function query() on null in C:\wamp64\www\Blog\App\Table\Table.php on line 18).
Ma classe categorie:
et enfin ma classe Table :
<div class="col-sm-4">
<ul>
<?php foreach(\App\Table\Categorie::all() as $categorie): ?>
<li><a href="<?= $categorie->url; ?>"><?= $categorie->titre; ?></a></li>
<?php endforeach; ?>
</ul>
</div>
Erreur afficher Fatal error: Call to a member function query() on null in C:\wamp64\www\Blog\App\Table\Table.php on line 18).
Ma classe categorie:
<?php
namespace App\Table;
use App\App;
class Categorie extends Table{
protected static $table ='categories';
public function getURL(){
return 'index.php?p=categorie&id='.$this->id;
}
}
et enfin ma classe Table :
<?php
namespace App\Table;
use App\App;
class Table {
protected static $table;
private static function getTable(){
if(static::$table === null){
$class_name = explode('\\',get_called_class());
static::$table = strtolower(end($class_name)).'s' ;
}
return static::$table;
}
public static function all(){
return App::getDB()->query("
SELECT *
FROM {static::getTable()}
",get_called_class());
}
public function __get($key){
$method = 'get' . ucfirst($key);
$this->$key =$this->$method();
return $this->$key;
}
}