Sepulturaさんがコメントしたリンクには、フィルタを有効/無効にする方法と独自のカスタムフィルタを書き込む方法の例があります。
From the docs
例フィルタ:
<?php
namespace Example;
use Doctrine\ORM\Mapping\ClassMetaData,
Doctrine\ORM\Query\Filter\SQLFilter;
class MyLocaleFilter extends SQLFilter
{
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
{
// Check if the entity implements the LocalAware interface
if (!$targetEntity->getReflectionClass()->implementsInterface('LocaleAware')) {
return "";
}
return $targetTableAlias.'.locale = ' . $this->getParameter('locale'); // getParameter applies quoting automatically
}
}
ドキュメントも(そう、あなたがそれを無効/有効にすることができます)このフィルタを追加するために、次のコード行を使用するように言う:
$config->addFilter("locale", "\Doctrine\Tests\ORM\Functional\MyLocaleFilter");
しかし、このフィルタをどこにでも使用したい場合は、このコード行をあらゆる場所で必要な場所に配置し、$config
にアクセスする必要がありますDoctrineのConfiguration
オブジェクトがあります)。
あなたがコア/ MVCモジュールまたはアプリケーションの構成に以下の構成を追加することができZend Frameworkの2及び3において
:
'doctrine' => [
'configuration' => [
'orm_default' => [
'filters' => [
'locale' => MyLocaleFilter::class,
],
],
],
],
コードと構成の上の行このフィルタを有効に、Aに無効にします特定の場所、あなたは()最初は&設定するを可能にします(ドキュメントごとに)無効にする次の行を使用します。//docs.doctrine-:
<?php
$filter = $em->getFilters()->enable("locale");
$filter->setParameter('locale', 'en');
// Disable it
$filter = $em->getFilters()->disable("locale");
多分あなたはDoctring SQLFilter(HTTPを使用して、独自のフィルタを書くことができますproject.org/projects/doctrine-orm/en/latest/refere nce/filters.html)? – Sepultura
これを解決できましたか? – Nukeface
私は@Nukefaceをやったとは思わない - それについて考えてみると、これは本当にソフト削除の有効な使い方であるとは思わない(真の削除と同じように扱うべきだから)。これを処理するカスタムプロパティとdoctrineフィルタ –