corso https://vola.udemy.com/course/php-mvc-from-scratch/learn/lecture/40931984#overview
filippo.bertilotti
2024-05-21 a26040f4846abcc8a8f8e81eb2d6d7923c384fdb
funzione getTable che permette di prendere il nome della tabella (parte 122)
1 files modified
10 ■■■■ changed files
src/Framework/Model.php 10 ●●●● patch | view | raw | blame | history
src/Framework/Model.php
@@ -6,14 +6,18 @@
    abstract class Model
    {
        protected ?string $table;
        public  function __construct(private Database $database) {
        private function getTable() {
            $parts = explode("\\", $this::class);
            return strtolower(array_pop($parts));
        }
        public  function __construct(private Database $database) {
        }
        public function findAll(): array|bool
        {
            $pdo = $this->database->getConnection();
            $sql = "SELECT * FROM {$this->table}";
            $sql = "SELECT * FROM {$this->getTable()}";
            $stmt = $pdo->query($sql);
@@ -23,7 +27,7 @@
        public function find(string $id) {
            $conn = $this->database->getConnection();
            $sql = "SELECT *
                    FROM {$this->table}
                    FROM {$this->getTable()}
                    WHERE id = :id";
            $stmt = $conn->prepare($sql);
            $stmt->bindValue(":id", $id, PDO::PARAM_INT);