gpt4 book ai didi

php - 在 Sonata-Admin 全局搜索中搜索哪些列

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:38:27 25 4
gpt4 key购买 nike

Sonata Admin 中的全局搜索选项搜索所有具有与之关联的管理类的 (doctrine2) 实体。

我想弄清楚的是如何配置全局搜索搜索的列。在我的客户网站上,它似乎正在搜索所有 VARCHAR 字段(原则类型:字符串)而不是 TEXT 字段(原则类型:文本)。

有人知道为什么会这样吗?如何改变?

最佳答案

根据 sonata admin 的文档,他们提到全局搜索模块将搜索所有可见的管理员,即 show_in_dashboard 设置为 true,它将仅搜索配置管理员的 中的那些字段>configureDatagridFilters()函数,所以添加到admin类的$datagridMapper对象的字段会在Sonata admin的全局搜索中被搜索。

例如,您有新闻管理员,在 configureListFields() 中您有 3 个字段

protected function configureListFields(ListMapper $listMapper)
{
$listMapper
->addIdentifier('id')
->add('name')
->add('createdDate');
}

并且在 configureDatagridFilters() 中,您只有名称字段来过滤结果

protected function configureDatagridFilters(DatagridMapper $datagridMapper)
{
$datagridMapper->add('name');
}

所以Sonata只会搜索你的新闻管理员的名字字段,因为你为这个管理员配置了一个过滤器,所以这个过滤器也用于管理员的全局搜索,除了名字字段不会搜索其他字段


根据文档

The "global search" allows the end user to iterate over all visible admins in the dashboard and search for the keyword. The current implementation is very simple, every filter related to a string will be searchable by default.

ADMIN BUNDLE ~ GLOBAL SEARCH


关于奏鸣曲全局搜索的其他信息是

The search iterates over admin classes and look for filter with the option global_search set to true. If you are using the SonataDoctrineORMBundle any text filter will be set to true by default.

默认情况下,sonata 会查找字段描述,如果设置为字符串,它会自动参与全局搜索,您还可以通过在 $datagridMapperadd 中设置字段选项来强制在搜索中使用字段()如下所示

->add('name', null, array('global_search' => true), null, array()

Sonata Search

关于php - 在 Sonata-Admin 全局搜索中搜索哪些列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25909103/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com