progetto fatto precedentemente adattato al framework creato con il corso
filippo.bertilotti
2024-06-05 15e03a88fa42f2444138ebc6f171c9a32a3a4238
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
<?php
    namespace App\Models;
 
    use App\Database;
    use PDO;
    use Framework\Model;
    class Product extends Model {
        //protected ?string $table = "product";
        
 
        protected function validate(array $data): void {
            
            if(empty($data["name"])) {
                $this->addError("name","Name is required");
            }
        }
 
        public function getTotal() : int {
            $sql = "SELECT COUNT(*) AS total FROM product";
            $conn = $this->database->getConnection();
            $stmt = $conn->query($sql);
            $row = $stmt->fetch(PDO::FETCH_ASSOC);
 
            return (int) $row["total"];
 
 
        }
    }