DAO files in PHP required?

Asked

Viewed 305 times

0

I wonder if DAO classes are required in PHP?

Ex: Productodao

I see many people programming without putting same DAO files on a MVC platform.

I am learning Object-Oriented programming at my college, and the teacher directs the user to create DAO files for separation of responsibilities.

Listening to a @Hipster podcast, I noticed that the developers of @stackoverflow put querys right into the controller. That’s also cool?

  • @rray I read this post. Despite being almost the same thing, I funnelled the issue focusing on PHP.

  • When we bring the concepts of good practice to the community, what can we find by surprise? We know that a large part of the PHP community still has bad practice. And I don’t know if that’s right, because I’ve come across a lot of systems in a large company, and I find a lot of things that I don’t believe in!

  • 2

    The concept of DAO is language dependent, the answer in Java will be the same for PHP. "Principles" in theory are state-of-the-art. However, it is not the same thing in practice. You will find wrong things in small, medium and large companies.

  • If you do not put the database access logic in a dao it is likely to put in a model :). The idea is to centralize these operations in a class if you put them right into the controller and it’s difficult to reuse and spread this code throughout the application. In the cast it also says that this solution is adopted by performace since abstractions have a cost (it may be a little too much).

1 answer

2

An DAO is not connected to the MVC or belonging to the PHP, but you commonly see the two being employed together DAO and MVC and also it is common to see DAO on PHP as it is a good practice. DAO is correct if related to a Model of the pattern.

THE DAO, date access Object, as the name says, it deals with the connections of a model with its persistence, an SGBD as Postgresql or even half text files for example, so it is common to be confused with Controller, but this wrong.

Follow an example links:

http://www.guj.com.br/t/padrao-dao-e-mvc/274701/7

  • Cool! Speaking about performance... Would it be significant to do this tour between responsibilities? Happens here in Stackoverflow! They create the query inside the controller, not inside a model. This would lose performance?

  • Well, I guess that doesn’t influence it so much, but it hurts the MVC standard itself, it’s not good practice.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.