A
A
Anton2016-11-15 18:38:03
Silex
Anton, 2016-11-15 18:38:03

How to work with data?

Hello. I started using silex and the question arose of how to work with data in it, I heard that there are some providers, but it's not entirely clear how it works. In general, I need a certain class that encapsulates the work with data, and in order to use its methods in controllers in the future. How to implement it correctly in silex?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2016-11-18
Reytarovsky @Antonchik

the question arose how to work with data in it

In any way convenient for you. SIlex is a dumb http framework, it doesn't provide anything out of the box for working with a database. Use at least PDO at least any ORM.
Service providers, they are used to register dependencies. Read the documentation.
This is not one class, as a rule, far from one. Or read about DAO/TableGateway.
Controllers serve one purpose. Convert the result of the application's work into an HTTP response or form an application call from an HTTP response. Well, that is, an "application" is just some kind of php code. With the help of service providers, you can register code in the dependency container and take the required one in the controllers.
Try to understand first what is a service locator, dependency injection, inversion of control... And don't think that there is a "correct" way to work with a database in silex. There's just no database work out of the box.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question