我正在嘗試使用 Symfony 6 設定 Easy Admin 4,所以我composer require easycorp/easyadmin-bundle按照檔案所述進行了操作。
作曲家創建DashboardController.php我有以下代碼:
<?php
namespace App\Controller\Admin;
use App\Entity\User;
use EasyCorp\Bundle\EasyAdminBundle\Config\Dashboard;
use EasyCorp\Bundle\EasyAdminBundle\Config\MenuItem;
use EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class DashboardController extends AbstractDashboardController
{
#[Route('/admin', name: 'admin')]
public function index(): Response
{
return parent::index();
// Option 1. You can make your dashboard redirect to some common page of your backend
//
// $adminUrlGenerator = $this->container->get(AdminUrlGenerator::class);
// return $this->redirect($adminUrlGenerator->setController(OneOfYourCrudController::class)->generateUrl());
// Option 2. You can make your dashboard redirect to different pages depending on the user
//
// if ('jane' === $this->getUser()->getUsername()) {
// return $this->redirect('...');
// }
// Option 3. You can render some custom template to display a proper dashboard with widgets, etc.
// (tip: it's easier if your template extends from @EasyAdmin/page/content.html.twig)
//
// return $this->render('some/path/my-dashboard.html.twig');
}
public function configureDashboard(): Dashboard
{
return Dashboard::new()
->setTitle('La boutique Fran?aise');
}
public function configureMenuItems(): iterable
{
yield MenuItem::linkToDashboard('Dashboard', 'fa fa-home');
// yield MenuItem::linkToCrud('Utilisateurs', 'fas fa-list', User::class);
}
}
現在,帶有紅色下劃線的AbstractDashboardController avec 收到了這個警告:Undefined type 'EasyCorp\Bundle\EasyAdminBundle\Controller\AbstractDashboardController'
由于缺少 AbstractDashboardController ,因此類等都return parent::...不起作用。Dashboard
知道如何解決這個問題嗎?在其他帖子中沒有找到任何答案。
謝謝 !
uj5u.com熱心網友回復:
首先,parent::index();只會顯示包的默認索引頁面。就像函式注釋中所說的那樣,您必須選擇要回傳的內容。例如,現在,我的index功能只有:
return $this->render('admin/dashboard.html.twig');
我的樹枝檔案包含:
{% extends '@EasyAdmin/layout.html.twig' %}
但是,您的檔案看起來不錯(我也有同樣的東西)。也許做一個php bin/console cache:clear和服務器重啟會解決你的問題?
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/488269.html
上一篇:值之間的Symfony約束集合
下一篇:如何在DQL中僅按年份分組?
