summaryrefslogtreecommitdiff
path: root/src/model/Model.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/model/Model.php')
-rw-r--r--src/model/Model.php13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/model/Model.php b/src/model/Model.php
index 17d1292..3fb3bdf 100644
--- a/src/model/Model.php
+++ b/src/model/Model.php
@@ -43,7 +43,7 @@ abstract class Model extends DB
43 foreach($data as $key => $value) 43 foreach($data as $key => $value)
44 { 44 {
45 // nom du setter 45 // nom du setter
46 // nom_du_champ devient setNomDuChamp 46 // nom_propriete => setPropriete
47 // on sépare les mots par des espaces, ucwords met la première lettre de chaque mot en majuscule, puis on supprime les espaces 47 // on sépare les mots par des espaces, ucwords met la première lettre de chaque mot en majuscule, puis on supprime les espaces
48 $setter_name = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))); // ucwords: première lettre de chaque mot en majuscule 48 $setter_name = 'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key))); // ucwords: première lettre de chaque mot en majuscule
49 if(method_exists($this, $setter_name)) 49 if(method_exists($this, $setter_name))
@@ -207,7 +207,7 @@ abstract class Model extends DB
207 207
208 208
209 // update UPDATE 209 // update UPDATE
210 public function update(int $id) 210 public function update(int $id) // utiliser plutôt $this->ID ?
211 { 211 {
212 $fields = []; 212 $fields = [];
213 $values = []; 213 $values = [];
@@ -219,13 +219,18 @@ abstract class Model extends DB
219 $values[] = $value; 219 $values[] = $value;
220 } 220 }
221 } 221 }
222 $values[] = $id; 222 $values[] = $id; // cette syntaxe ajoute une valeur au tableau
223 $field_list = implode(', ', $fields); 223 $field_list = implode(', ', $fields);
224 224
225 // UPDATE annonces SET titre = ?, description = ?, actif = ? WHERE id= ? 225 // UPDATE annonces SET titre = ?, description = ?, actif = ? WHERE id = ?
226 return($this->execQuery('UPDATE ' . $this->table . ' SET ' . $field_list . ' WHERE id = ?', $values)); 226 return($this->execQuery('UPDATE ' . $this->table . ' SET ' . $field_list . ' WHERE id = ?', $values));
227 } 227 }
228 228
229 public function updateOneValue(string $field, $value)
230 {
231 return($this->execQuery('UPDATE ' . $this->table . ' SET ' . $field . ' = ? WHERE id = ?', [$value, $this->ID]));
232 }
233
229 234
230 // delete DELETE 235 // delete DELETE
231 protected function delete(int $id) 236 protected function delete(int $id)