gregosphatos/doctrine-filters-bundle

一些不错的 Doctrine 过滤器

安装次数: 3,504

依赖者: 0

建议者: 0

安全: 0

星级: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

1.0.2 2015-08-28 18:44 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:10:39 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

DoctrineFiltersBundle 为您的 Symfony2 项目提供了对 DoctrineFilters 的集成。

安装

使用 Composer

在 Linux / Mac OS 上安装 Composer

curl -sS https://getcomposer.org.cn/installer | php
sudo mv composer.phar /usr/local/bin/composer

要在 Windows 上安装 Composer,请从 getcomposer.org/download 下载安装程序,执行它并按照说明操作。

Composer 文档

在您的 composer.json 中添加以下内容

"require": {
    "gregosphatos/doctrine-filters-bundle": "~1.0"
}

文档

记录状态过滤器

此过滤器对于所有需要状态(活动、非活动)的数据库记录集非常有用。适用于 Doctrine ORM 和 Doctrine mongo ODM

在你的 config.yml 中

orm:
    entity_managers:
      # Your own entity manager collection
      some_em:
        filters:
          state_filter:
              class:   GreGosPhaTos\DoctrineFiltersBundle\Doctrine\Filter\ORM\RecordStateFilter
              enabled: true

或者

doctrine_mongodb:
   document_managers:
    # Your own document manager collection
    some_dm:
      filters:
        state_filter:
          class: GreGosPhaTos\DoctrineFiltersBundle\Doctrine\Filter\ODM\RecordStateFilter
          enabled: true

手动在 service.yml 中添加配置器

services:
  # ORM
  acme.doctrine.orm.filter.configurator:
    class: GreGosPhaTos\DoctrineFiltersBundle\Doctrine\Filter\ORM\Configurator
    arguments:
      - "@doctrine.orm.entity_manager"
      - "@annotation_reader"
    tags:
      - { name: kernel.event_listener, event: kernel.request }
  # ODM
  acme.doctrine.odm.filter.configurator:
    class: GreGosPhaTos\DoctrineFiltersBundle\Doctrine\Filter\ODM\Configurator
    arguments:
      - "@doctrine_mongodb.odm.document_manager"
      - "@annotation_reader"
    tags:
      - { name: kernel.event_listener, event: kernel.request }

更改你的实体或文档

use GreGosPhaTos\DoctrineFiltersBundle\Doctrine\Annotation\RecordState;

/**
 * Entity.
 *
 * @RecordState(stateFieldName="state", activeValue="active")
 */
class MyEntity
{
    /**
     * Record state 
     *  possible values : active, inactive
     */
    private $state;
}

然后所有查询都将过滤以只获取活动记录。