我開發了一個以 EasyAdmin 作為后端的在線學習網站。一切正常,但我想隱藏或禁用 crud 頁面頂部的搜索欄。我沒有覆寫任何模板,只是根據我的帶有欄位的物體和自定義查詢構建器創建了 crud,以僅索引登錄用戶創建的內容。似乎無法在網上或檔案中找到有關如何操作的任何資訊。是否可以添加隱藏或禁用默認搜索欄的選項?謝謝!
uj5u.com熱心網友回復:
https://symfony.com/doc/3.x/EasyAdminBundle/crud.html#search-order-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://www.uj5u.com/gongcheng/467721.html
下一篇:正確宣告變數時出現“未找到”錯誤
