评论Sepulura的链接给出了一些关于如何启用/禁用过滤器和编写自己的自定义过滤器的示例。
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
(其中c来自Doctrine的Configuration
对象)。
在Zend框架2和3中可以添加下面的配置到核心/ MVC模块或应用程序中的配置:
'doctrine' => [
'configuration' => [
'orm_default' => [
'filters' => [
'locale' => MyLocaleFilter::class,
],
],
],
],
上面的代码线和配置使此过滤器,在禁用具体位置,请使用您要禁用以下行(每个文档(第一个能够提供配置&)):
<?php
$filter = $em->getFilters()->enable("locale");
$filter->setParameter('locale', 'en');
// Disable it
$filter = $em->getFilters()->disable("locale");
也许你可以编写使用Doctring名为sqlfilter(HTTP自己的过滤://docs.doctrine- project.org/projects/doctrine-orm/en/latest/refere NCE/filters.html)? – Sepultura
你是否设法解决这个问题? – Nukeface
我不认为我做了@Nukeface - 考虑它,我不认为这真的是一个真正的软删除的有效用法(因为它应该被视为一个真正的删除),所以我可能会实现一个自定义属性和原则过滤器来处理这个问题 –