probleme de recupération de donnéees
bonjour la communauté,
j'ai un soucis avec le code suivant...
Il fonctionne bien (bien qu'il soit largement perfectible, je suis débutant en php/poo/pdo), quand je place un var_dump($this) à la fin de la bouche FOREACH, ma fiche ressort bien sous la forme d'un array.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| <?php
require 'class/connect.php';
class Model extends connect {
public $table;
public $data;
public $connect;
function __construct(){
$this->connect = parent::__construct();
}
public function fiche($id){
$texte="SELECT * FROM ".$this->table." WHERE id=$id ORDER BY id LIMIT 1";
$sql = $this->connect->prepare($texte);
$sql->execute();
foreach ($sql as $key => $value) {
$this->$key= $value;
};
var_dump($this);
}
static function load($name){
require("$name.php");
return new $name();
}
}
?> |
le problème vient de mon fichier index.php
Code:
1 2 3 4 5 6 7 8 9 10 11
| <?php
require_once('class/model.php');
$adherents = Model::load("adherents");
$adherents->fiche(2);
echo $adherents->nom;
?> |
le echo me renvoie "Notice: Undefined property: adherents::$nom"...
Je ne dois pas comprendre un truc dans la manipulation des données d'un array en POO...
Merci de votre aide...