[POO] Utilisation de simplexml_element
Bonsoir,
je me mets à la POO dans PHP5 et j'ai un problème avec ma classe qui n'a pour but de lire un fichier xml et de renvoyer quelques infos.
Dans le constructeur je peux accéder aux infos sans problème, comme
echo $xml->projet[0]->titre;
Mais dans la méthode afficheXML() ça ne va plus...
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| <?php
class InfosXML{
private $xml;
public function __construct($url){
if (file_exists($url)){
$xml = simplexml_load_file($url);
echo $xml->projet[0]->titre;
}
else
echo"Le fichier $url n'a pas été trouvé!";
}
public function afficheXML(){
$xmlTmp = $this->xml;
foreach($xmlTmp->projet as $cle=>$val){
echo "Titre : $val->titre $val->vignette $val->fichier.</br>"; //Notice: Trying to get property of non-object in InfosXML.php on line 17
}
echo $this->xml->projet[0]->titre; //Notice: Trying to get property of non-object in InfosXML.php on line 19
}
}
?> |
Si quelqu'un voit là où je me gourre...
Merci,
Philippe.