Confused about how model are used


I’m actually following the tutorial (the blog) and I’m a bit confuse about the models/db interaction.

We create a PostCommandInterface and inside we define 3 methods. Then, we implements this interface in the class PostCommand but we didn’t implement the 3 methods here. Then we create a ZendDbSqlCommand class and here we implements again the PostCommandInterface but this time we define and implement the 3 methods.

My question is, why do we have an empty class PostCommand if we don’t write any code in it ?

I think I’ve missed something important about the design of our application :thinking:.

Any help would be welcome :slight_smile:

Hello and welcome to the forum! :smiley:

The explanation can be found in a sentence before the code example:

Let’s create a dummy implementation, as we did when we first started working with repositories.

Two classes have been created in the model and databases section:

  1. PostRepository
  2. ZendDbSqlRepository

And at the end, only the last implementation was used.

The same procedure is now used for the implementation of the command interface:

  1. PostCommand
  2. ZendDbSqlCommand

The empty PostCommand class is used to display the form in the next steps of the tutorial. The real implementation is used to work with the database.

I hope this helps for your understanding.

Thanks for the feedback.

I understand why we needed a dummy PostRepository (to have fake data with an array), but right now if I delete both PostCommand.php and PostRepository.php my application still work without a problem.

One more question, ZendDbSqlRepository isn’t supposed to be called ZendDbSqlPostRepository ? Since in a blog we can have a repository for comments or categories ?