我很难理解我应该如何在 easyadmin 3.3 中进行自定义过滤器。文档没有帮助。我总是收到错误错误:类 App\Entity\entity1 没有名为“field1”的字段或关联
所以我试图将映射设置为 false 以防止这种情况发生,遵循文档,我得到了这个
试图调用“App\Controller\Admin\Filter\customfilter”类的名为“mapped”的未定义方法。
这是我的代码: Crud 控制器:
public function configureFilters(Filters $filters): Filters
{
return $filters
->add(getAutoclaveFilter::new('fiedWithNoAssociation')->mapped(false))
;
}
自定义过滤器:
class GetAutoclaveFilter implements FilterInterface
{
use FilterTrait;
public static function new(string $propertyName, $label = null): self
{
return (new self())
->setFilterFqcn(__CLASS__)
->setProperty($propertyName)
->setLabel($label);
}
public function apply(QueryBuilder $queryBuilder, FilterDataDto $filterDataDto, ?FieldDto $fieldDto, EntityDto $entityDto): void
{
$queryBuilder->andWhere(sprintf('%s.%s = :value', $filterDataDto->getEntityAlias(), $filterDataDto->getProperty()))
->setParameter('value',$filterDataDto );
}
和实体:
public function fiedWithNoAssociation()
{
return $this->getEntityAssociated()->getEntity2();
}
我做错了什么?映射功能还没有实现吗?