Bonjour, je dois insérer des brèves ou des filets dans une bdd :

J'ai insérer une première brève & je l'ai ensuite afficher avec les Getters -> OK
J'ai ensuite demander à supprimer une brève(1) -> OK
J'ai ensuite demander à mettre à jour la valeur de l'attribut texte -> NO


Message d'erreur -> Fatal error: Uncaught Error: Call to undefined method Post::getTitle()
Voici mon code :

postManager.php

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
 
 
<?php 
 
class postManager {
 
	private $_db;
 
	public function __construct($db) {
 
		$this->setDb($db);
    }
 
    public function setDb(PDO $dbh) {
 
    	$this->_db = $dbh;
    }
 
    public function addPost(Post $post) {
 
        if(!method_exists($post, 'getTitle')) {
 
            $sql = 'INSERT INTO post (texte, dt_creation) VALUES(:texte, :dt_creation)';
 
            $stmnt = $this->_db->prepare($sql);
        }
        else {
 
            $sql = 'INSERT INTO post (texte, dt_creation, title) VALUES(:texte, :dt_creation, :title)';
 
            $title = htmlspecialchars($post->getTitle());
 
            $stmnt = $this->_db->prepare($sql);
            $stmnt->bindParam(':title', $title);
        }
 
        $texte = htmlspecialchars($post->getTexte());
        $dt_creation = $post->getDt_creation();
 
        $stmnt->bindParam(':texte', $texte);
        $stmnt->bindParam(':dt_creation', $dt_creation);
        $stmnt->execute();
    }
 
    public function getPost($id = '') {
 
        if(empty($id)) {
 
            $sql = 'SELECT id, texte, dt_creation, title FROM post';
 
            $stmnt = $this->_db->prepare($sql);
        }
 
        elseif(is_numeric($id)) {
 
            $sql = 'SELECT id, texte, dt_creation, title FROM post WHERE id = :id';
 
            $stmnt = $this->_db->prepare($sql);
            $stmnt->bindParam(':id', $id);
        }
 
        $stmnt->execute();
 
        while($row = $stmnt->fetch(PDO::FETCH_ASSOC)) {
 
            $result[] = $row;
        }
 
        return $result;
    }
 
    public function updatePost(Post $post) {
 
        $sql = 'UPDATE post SET texte = :texte, dt_creation = :dt_creation, title = :title WHERE id = :id';
 
        $id = $post->getId();
        $texte = $post->getTexte();
        $dt_creation = $post->getDt_creation();
        $title = $post->getTitle();
 
        $stmnt = $this->_db->prepare($sql);
        $stmnt->bindParam(':id', $id);
        $stmnt->bindParam(':texte', $texte);
        $stmnt->bindParam(':dt_creation', $dt_creation);
        $stmnt->bindParam(':title', $title);
        $stmnt->execute();
    }
 
    public function deletePost($id) {
 
        $sql = 'DELETE FROM post WHERE id = :id';
 
        $stmnt = $this->_db->prepare($sql);
        $stmnt->bindParam(':id', $id);
        $stmnt->execute();
 
        $count = $stmnt->rowCount();
 
        return $count;
    }
}
Display.php

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 
 
<?php
 
require('class/Post.php');
require('class/postManager.php');
 
$post_data = array(
 
	'id' => 1,
	'texte' => 'Texte pour le contenu',
	'dt_creation' => '2013-11-14'
);
 
$post = new Post($post_data);
var_dump($post);
 
$db = new PDO('mysql:host=localhost;dbname=dbpost', 'root', '10111110');
 
$manager = new postManager($db);
 
$manager->addPost($post);
 
echo $post->getId();
echo '<br>';
 
echo $post->getTexte();
echo '<br>';
 
echo $post->getDt_creation();
echo '<br><br>';
 
$deletePost = $manager->deletePost(1);
echo $deletePost; 
 
$current_post = $manager->getPost(2);
var_dump($current_post);
 
$new_content = array(
 
	'id' => (int) $current_post[0]['id'],
	'texte' => $current_post[0]['texte'],
	'dt_creation' => $current_post[0]['dt_creation']
);
 
$post_to_update = new Post($new_content);
 
$post_to_update->setTexte('Nouveau contenu de la brève');
 
$manager->updatePost($post_to_update);
 
$check_post = $manager->getPost(2);
var_dump($check_post);
Post.php

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
 
 
<?php
 
class Post {
 
	protected $id;
    protected $texte;
    protected $dt_creation;
 
	public function __construct(array $data) {
 
		$this->setId($data['id']);
        $this->setTexte($data['texte']);
        $this->setDt_creation($data['dt_creation']);
    }
 
	public function setId($id) {
 
		if((is_int($id)) AND ($id > 0)) {
 
			$this->id = $id;
        }
	}
 
	public function setTexte($texte) {
 
		if(is_string($texte)) {
 
			$this->texte = $texte;
        }
	}
 
	public function setDt_creation($dt_creation) {
 
		list($y, $m, $d) = explode("-", $dt_creation);
 
		if(checkdate($m, $d, $y)) {
 
			$this->dt_creation = $dt_creation;
        }
	}
 
	public function getId() { 
 
		return $this->id;
	}
 
	public function getTexte() {
 
		return $this->texte;
	}
 
	public function getDt_creation() {
 
		return $this->dt_creation;
	}
}
 
class Breve extends Post {
 
}
 
class Filet extends Post {
 
	protected $title;
 
    public function __construct(array $data) {
 
    	parent::__construct($data);
 
    	$this->setTitle($data['title']);
    }
 
    public function getTitle() {
 
    	return $this->title;
    }
 
    public function setTitle($title) {
 
    	if(is_string($title)) {
 
    		$this->title = $title;
        }
    }
}
Merci pour votre aide.