禁用或隐藏EasyAdmin Crud搜索栏

发布于 2025-01-22 09:07:59 字数 170 浏览 6 评论 0 原文

我已经开发了一个以EasyAdmin为后端的在线学习网站。一切正常,但是我想隐藏或禁用Crud页面顶部的搜索栏。我还没有覆盖任何模板,只是基于我的实体创建了带有字段和自定义查询构建器的CRUD来仅通过登录用户创建的索引内容。 似乎找不到有关如何在线或在文档中进行操作的任何信息。是否可以添加隐藏或禁用默认搜索栏的选项?谢谢你!

I have developped an online learning website with EasyAdmin as backend. Everything works fine, but I'd like to hide or disable the search bar on top of the crud pages. I have not overridden any templates, just created crud based on my entities with fields and a custom query builder to only index content created by the logged in user.
Can't seem to find any info on how to do it online or in the doc. Is it possible to add an option to hide or disable the default search bar? Thank you!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑梦风尘 2025-01-29 09:07:59

https://symfony.com/ doc/3.x/easyadminbundle/crud.html#search-order-and-and-pagination-options

在您的仪表板中:

# App\Controller\Admin\DashboardController

public function configureCrud(): Crud
{
    $crud = Crud::new();
    return $crud
        // ...
        ->setSearchFields(null); // hide the search bar on all admin pages
}

这就是您所要求的。但是您可以走得更远:

- >仅在特定的crudController上隐藏搜索栏:

# App\Controller\Admin\PostCrudController

public function configureCrud(Crud $crud): Crud
{
    return $crud
        // ...
        ->setSearchFields(null); // hide the search bar on admin pages related to the Post entity
}

- >添加颗粒控制条件:

# App\Controller\Admin\PostCrudController

public function configureCrud(Crud $crud): Crud
{
    if (
        $_GET['crudAction'] === Action::EDIT // if this is the 'edit' page
        || !in_array('ROLE_ADMIN', $this->getUser()->getRoles()) // or if the user is not an admin
    ) {
        $crud->setSearchFields(null); // then hide the search bar
    }
    return $crud;
}

https://symfony.com/doc/3.x/EasyAdminBundle/crud.html#search-order-and-pagination-options

In your Dashboard:

# App\Controller\Admin\DashboardController

public function configureCrud(): Crud
{
    $crud = Crud::new();
    return $crud
        // ...
        ->setSearchFields(null); // hide the search bar on all admin pages
}

That's what you asked for. But you can go further:

-> Hide the search bar only on a specific CrudController:

# App\Controller\Admin\PostCrudController

public function configureCrud(Crud $crud): Crud
{
    return $crud
        // ...
        ->setSearchFields(null); // hide the search bar on admin pages related to the Post entity
}

-> Add conditions for granular control:

# App\Controller\Admin\PostCrudController

public function configureCrud(Crud $crud): Crud
{
    if (
        $_GET['crudAction'] === Action::EDIT // if this is the 'edit' page
        || !in_array('ROLE_ADMIN', $this->getUser()->getRoles()) // or if the user is not an admin
    ) {
        $crud->setSearchFields(null); // then hide the search bar
    }
    return $crud;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文