0

I am trying to create simple database abstraction layer. I read a lot of articles about Active Record and Table Data Gateway and right now I am very confused.

I think that I understand some theory (small) about them but not how exactly to implement them. I have choosed to implement Data Table Gateway. I will try to explain what I did and if you give me some advices I will be glad. I am not sure why (for example in ZF2) every time I have to use Table Data Gateway like DI in the models.

In my case my AbstractModel just get DbAdapter in the constrictor by IoC container but I am not sure that this is ok. Ok I will describe my situation. I have following classes:

  • DbAdapter -> it creates db connection (using PDO)
  • IoC (Inversion of Control Container)
  • AbstractModel -> in constructor I get DbAdapter using IoC. This means that it hold only one instance of DbAdapter. In this class I also have CRUD methods.
  • Another classes represent the tables in db. For example class User extends AbstractModel and has method getTable which return the name of the table. Another sql queries will be in this classes which represent the tables. These classes have access to DbAdapter.

Is it ok this scheme and how can I improve it?

edigu
  • 9,380
  • 5
  • 53
  • 77
Anton_Sh
  • 225
  • 1
  • 7
  • 14

0 Answers0