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::$connections$this->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::$connections$this->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