2

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); } 
1
  • No. Model is a layer. Commented May 10, 2014 at 12:36

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks so the dao files I have now should go in the model folder if I use CakePhp for example?
Yes and no. Cake does not do MVC correctly. Cake's model essentially is a DAO and nothing more.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.