在模块内执行 Doctrine Dbal 查询的存储库

Repository to execute Doctrine Dbal queries inside module

我的目标是能够从 PS 1.7.4.2 模块中执行 SQL 查询。鼓励文档使用 Doctrine Dbal 服务。

来自documentation

Even if using old way to retrieve data is still valid (Product::getProducts or through the webservice), we’d like to introduce a best practice here: using a repository and get ride of the Object model. This has a lot of advantages, you rely on database instead of model and you’ll have better performances and control on your data.

如果我将存储库 class 放在 src/Prestashop/Entity/Repository 中,我认为这不符合 PS 理念。那么存储库 class 放在哪里?

通过在模块内执行 composer init 并将模块中的 src 映射到 Foo 命名空间来解决问题。

然后在模块文件里面,你可以从容器访问服务,即Doctrine服务。

您还可以将自己的存储库 类 定义为服务并从容器中获取它们。