Question

In our Backend course at school we gradually learned about working with MVC structure for PHP development.

Our basic 'template' consists of an index.php (which has routes to the pages & functions in the controller), controller folder (containing controllers), view folder and a DAO folder containing one for general acces to the database and files relative to each table in the database.

In this structure I have Controller and View but I wondered why we never use Model, we were never even told about it… Is the DAO what should be my Model folder?

Below is an example of DAO code for getting values from a products table, just to make it clear what I mean by DAO.

public function selectById($id) {
    $sql = "SELECT * FROM `products` WHERE `id` = :id";
    $stmt = $this->pdo->prepare($sql);
    $stmt->bindValue(':id', $id);
    $stmt->execute();
    return $stmt->fetch(PDO::FETCH_ASSOC);
}
Was it helpful?

Solution

No, a DAO is not the Model. The DAO is a part of the Model if anything.

The Model is not one single thing. The Model is basically the core of your entire application; it is the application. The Model contains everything that makes up what your application does. It encompassed the database, the database access layer, business objects, business logic, auxiliary services... everything that makes your application unique.

The View is what presents this core application to the outside, allows people to see and interact with what your application does. There may be several different Views for different usage scenarios. The Controller is the remaining glue that orchestrates how the outside world, the View and the core Model work together.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top