problème dans le tuto Développer un site de A à Z 2 jour

Par laila, il y a 14 ans


Bonjour tout le monde
je suis dans le temps 43 min 39 s de la vidéo Développer un site de A à Z jour n°2 mes fichiers sont:
f1:pagescontroller.php
<?php

class Pagescontroller extends controller{
function view($id){

this->loadmodel('Post'); $d'page'] = $this->Post->findfirst(array( 'conditions' => array('id'=>id,'type'=>'page')
)) ;

if(empty(d'page'])){ $this->e404('page introuvable'); } $this->set(d) ;
}

}
?>
f2:model.php
<?php
class model{
static $connections=array();
public $conf='default';
public $table = false;
public $db;

public function __construct(){

conf = conf::databases$this->conf] ;

if(isset(model::connectionsthis->conf])){
this->db = model::connections$this->conf];

return TRUE;
}

try {
pdo= new PDO('mysql:host='.conf'host'].';dbname='.conf'database'].';', $conf'login'],conf'password'],array
(PDO::MYSQL_ATTR_INIT_COMMAND =>'SET NAMES utf8')) ;
pdo->setAttribute(PDO::ATTR\_ERRMODE,PDO::ERRMODE\_WARNING); model::connectionsthis->conf]=pdo;
$this->db = $pdo;

}
catch (PDOException $e){

if(conf::debug >=1){ die(e->getMessage());
}else {
die('impossible de se connecter à la base de donnée');
}

}
if ($this->table===FALSE){

this->table = strtolower(get\_class(this)).'s';
}
}
public function find($req){

sql = 'SELECT \* FROM '. $this->table.' as '.get\_class(this).'' ;
//consrtruction de la conditions

if(isset(req'conditions'])){ $sql.= ' WHERE '; if(!is\_array(req'conditions'])){
sql.=req'conditions'];
}else {
cond = array(); foreach (req'conditions']as k=>v){
if(!is_numeric(v)){ $v ='"'. mysql\_escape\_string(v).'"';
}

cond] = "k=v"; } $sql.= implode(' AND ',cond);

}
}
pre = $this->db->prepare(sql);
pre->execute(); return $pre->fetchAll(PDO::FETCH\_OBJ); } public function findFirst(req){
return current(this->find(req));

}
}
?>
f3:view.php
<?php title\_for\_layout =page->name ;?>
<h1><?php echo $page->name;?></h1>
<?php echo $page->content; ?>
tout fonctionne bien,quand j'ajoute ce ci: $pages= $this->post->find(array(
'conditions' => array('type'=>'page')
)); à mon pagescontroller.php comme ça:
<?php

class Pagescontroller extends controller{
function view($id){

this->loadmodel('Post'); $d'page'] = $this->Post->findfirst(array( 'conditions' => array('id'=>id,'type'=>'page')
)) ;

if(empty(d'page'])){ $this->e404('page introuvable'); } $pages= $this->post->find(array( 'conditions' => array('type'=>'page') )); $this->set(d) ;
}

}
?>
le message ci dessous apparait
( ! ) Notice: Undefined property: Pagescontroller::$post in C:\wamp\www\site_grafikar\controller\Pagescontroller.php on line 47

( ! ) Fatal error: Call to a member function find() on a non-object in C:\wamp\www\site_grafikar\controller\Pagescontroller.php on line 47
merci infiniment

2 réponses

djtec, il y a 14 ans

$this->post->find il faut un p majuscule à Post

laila, il y a 14 ans

merci beaucoup. Le problème est résolu