douruyun8153 2013-05-23 17:26
浏览 6

Doctrine2过滤器禁用/无效结果

I have a project that i'm currently migrating from pdo/sql to doctrine, but that's not based in any framework (shame).

I need to add many filters to the products entity, so the rows matched by these filters will never output anywhere in the frontend. The filters are for example: products out of stock, products with empty names, no pictures, no description, column "disabled" set to 1, etc...

How could i create this filter? Is there any example?

I dont think it would be a good solution to use findOneBy and add a multiple-index array with all conditions i need in every page. Also sometimes i update these filters and its not cool to update it everywhere the product entity is used in the project.

  • 写回答

1条回答 默认 最新

  • duan201444 2013-05-23 17:41
    关注

    Doctrine Filters:

    You can i.e. use Doctrine Filters to filter entities with deletedAt property not null ( softdeletable ):

    $config = new Doctrine\ORM\Configuration;
    // ... your configuration
    $config->addFilter('soft-deleteable', 'Gedmo\SoftDeleteable\Filter\SoftDeleteableFilter');
    

    Please have look at the source of the SoftDeletableFilter to understand how it works.

    More information can be found in the Filters section of the documentation.

    Furthermore:

    A very easy implementation of filterable repositories can be achieved with KnpLabs/DoctrineBehaviors.

    Please have a look at filterable.

    Uses traits so php >= 5.4 is needed!

    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效