类在Symfony 4中扩展了与EasyAdmin 3的不工作



我试图使Web应用程序与Symfony,我需要一个管理方面。但是,它不会工作,我没有看到任何答案,我的问题在任何网站上。

我有这个问题,每次我试图链接一个CRUD在我的菜单:

An exception has been thrown during the rendering of a template ("Unable to find the controller related to the "AppControllerAdminProducteur" Entity; did you forget to extend "EasyCorpBundleEasyAdminBundleControllerAbstractCrudController"?").

如果我仔细阅读它,我忘记了一个extends在一个文件,但我不知道在哪里。更重要的是,我用bundle生成这些文件,然后就会出现这个错误,而其他使用相同协议的人不会出现这个错误。

如果你看到什么,我把我的不同文件给你,因为我不能就这样被屏蔽而不完成我的实习。

Producteur.php


namespace AppEntity;
use AppRepositoryProducteurRepository;
use DoctrineORMMapping as ORM;
/**
* @ORMEntity(repositoryClass=ProducteurRepository::class)
*/
class Producteur
{
/**
* @ORMId
* @ORMGeneratedValue
* @ORMColumn(type="integer")
*/
private $id;
/**
* @ORMOneToOne(targetEntity=PtManufacturer::class, cascade={"persist", "remove"})
* @ORMJoinColumn(nullable=false, name="id_manufacturer", referencedColumnName="id_manufacturer")
*/
private $Nom;
/**
* @ORMColumn(type="string", length=255)
*/
private $courriel_User;
/**
* @ORMColumn(type="string", length=255)
*/
private $courriel_Corresp;
/**
* @ORMColumn(type="boolean")
*/
private $TVA_Appl;
/**
* @ORMColumn(type="string", length=20)
*/
private $Num_TVA;
/**
* @ORMColumn(type="text")
*/
private $Pied_De_Doc;
/**
* @ORMColumn(type="string", length=255)
*/
private $adresse1_E;
/**
* @ORMColumn(type="string", length=255, nullable=true)
*/
private $adresse2_E;
/**
* @ORMColumn(type="string", length=5)
*/
private $CP_E;
/**
* @ORMColumn(type="string", length=100)
*/
private $Ville_E;
/**
* @ORMColumn(type="string", length=255)
*/
private $adresse1_F;
/**
* @ORMColumn(type="string", length=255, nullable=true)
*/
private $adresse2_F;
/**
* @ORMColumn(type="string", length=5)
*/
private $CP_F;
/**
* @ORMColumn(type="string", length=100)
*/
private $Ville_F;
/**
* @ORMColumn(type="string", length=50)
*/
private $Num_Tel;
public function getId(): ?int
{
return $this->id;
}
public function getNom(): ?PtManufacturer
{
return $this->Nom;
}
public function setNom(PtManufacturer $Nom): self
{
$this->Nom = $Nom;
return $this;
}
public function getCourrielUser(): ?string
{
return $this->courriel_User;
}
public function setCourrielUser(string $courriel_User): self
{
$this->courriel_User = $courriel_User;
return $this;
}
public function getCourrielCorresp(): ?string
{
return $this->courriel_Corresp;
}
public function setCourrielCorresp(string $courriel_Corresp): self
{
$this->courriel_Corresp = $courriel_Corresp;
return $this;
}
public function getTVAAppl(): ?bool
{
return $this->TVA_Appl;
}
public function setTVAAppl(bool $TVA_Appl): self
{
$this->TVA_Appl = $TVA_Appl;
return $this;
}
public function getNumTVA(): ?string
{
return $this->Num_TVA;
}
public function setNumTVA(string $Num_TVA): self
{
$this->Num_TVA = $Num_TVA;
return $this;
}
public function getPiedDeDoc(): ?string
{
return $this->Pied_De_Doc;
}
public function setPiedDeDoc(string $Pied_De_Doc): self
{
$this->Pied_De_Doc = $Pied_De_Doc;
return $this;
}
public function getAdresse1E(): ?string
{
return $this->adresse1_E;
}
public function setAdresse1E(string $adresse1_E): self
{
$this->adresse1_E = $adresse1_E;
return $this;
}
public function getAdresse2E(): ?string
{
return $this->adresse2_E;
}
public function setAdresse2E(?string $adresse2_E): self
{
$this->adresse2_E = $adresse2_E;
return $this;
}
public function getCPE(): ?string
{
return $this->CP_E;
}
public function setCPE(string $CP_E): self
{
$this->CP_E = $CP_E;
return $this;
}
public function getVilleE(): ?string
{
return $this->Ville_E;
}
public function setVilleE(string $Ville_E): self
{
$this->Ville_E = $Ville_E;
return $this;
}
public function getAdresse1F(): ?string
{
return $this->adresse1_F;
}
public function setAdresse1F(string $adresse1_F): self
{
$this->adresse1_F = $adresse1_F;
return $this;
}
public function getAdresse2F(): ?string
{
return $this->adresse2_F;
}
public function setAdresse2F(?string $adresse2_F): self
{
$this->adresse2_F = $adresse2_F;
return $this;
}
public function getCPF(): ?string
{
return $this->CP_F;
}
public function setCPF(string $CP_F): self
{
$this->CP_F = $CP_F;
return $this;
}
public function getVilleF(): ?string
{
return $this->Ville_F;
}
public function setVilleF(string $Ville_F): self
{
$this->Ville_F = $Ville_F;
return $this;
}
public function getNumTel(): ?string
{
return $this->Num_Tel;
}
public function setNumTel(string $Num_Tel): self
{
$this->Num_Tel = $Num_Tel;
return $this;
}
}

ProducteurCrudController.php


namespace AppControllerAdmin;
use AppEntityProducteur;
use EasyCorpBundleEasyAdminBundleControllerAbstractCrudController;
class ProducteurCrudController extends AbstractCrudController
{
public static function getEntityFqcn(): string
{
return Producteur::class;
}
/*
public function configureFields(string $pageName): iterable
{
return [
IdField::new('id'),
TextField::new('title'),
TextEditorField::new('description'),
];
}
*/
}

DashboardController.php


namespace AppControllerAdmin;
use EasyCorpBundleEasyAdminBundleConfigDashboard;
use EasyCorpBundleEasyAdminBundleConfigMenuItem;
use EasyCorpBundleEasyAdminBundleControllerAbstractDashboardController;
use SymfonyComponentHttpFoundationResponse;
use SymfonyComponentRoutingAnnotationRoute;
class DashboardController extends AbstractDashboardController
{
/**
* @Route("/admin", name="admin")
*/
public function index(): Response
{
return parent::index();
}
public function configureDashboard(): Dashboard
{
return Dashboard::new()
->setTitle('Backoffice');
}
public function configureMenuItems(): iterable
{
return[
MenuItem::linktoDashboard('Dashboard', 'fa fa-home'),
MenuItem::linkToCrud('Producteur', 'fas fa-list', Producteur::class),
];
}
}

menu.html.twig

{% macro render_menu_item(item) %}
{% if item.isMenuSection %}
{% if item.icon is not empty %}<i class="menu-icon fa-fw {{ item.icon }}"></i>{% endif %}
<span class="{{ item.cssClass }}">{{ item.label }}</span>
{% else %}
<a href="{{ item.linkUrl }}" class="{{ item.cssClass }}" target="{{ item.linkTarget }}" rel="{{ item.linkRel }}" referrerpolicy="origin-when-cross-origin">
{% if item.icon is not empty %}<i class="menu-icon fa-fw {{ item.icon }}"></i>{% endif %}
<span>{{ item.label|raw }}</span>
{% if item.hasSubItems %}<i class="fa fa-fw fa-angle-right treeview-icon"></i>{% endif %}
</a>
{% endif %}
{% endmacro %}
{% block main_menu_before %}{% endblock %}
<ul class="sidebar-menu" data-widget="tree" data-animation-speed="250">
{% block main_menu %}
{% for menuItem in ea.mainMenu.items %}
{% block menu_item %}
<li class="{{ menuItem.isMenuSection ? 'header' }} {{ menuItem.hasSubItems ? 'treeview' }} {{ ea.mainMenu.isSelected(menuItem) ? 'active' }} {{ ea.mainMenu.isExpanded(menuItem) ? 'active submenu-active' }}">
{{ _self.render_menu_item(menuItem) }}
{% if menuItem.hasSubItems %}
<ul class="treeview-menu">
{% for menuSubItem in menuItem.subItems %}
{% block menu_subitem %}
<li class="{{ menuSubItem.isMenuSection ? 'header' }} {{ ea.mainMenu.isSelected(menuSubItem) ? 'active' }}">
{{ _self.render_menu_item(menuSubItem) }}
</li>
{% endblock menu_subitem %}
{% endfor %}
</ul>
{% endif %}
</li>
{% endblock menu_item %}
{% endfor %}
{% endblock main_menu %}
</ul>
{% block main_menu_after %}{% endblock %}

提前感谢您的帮助。

你应该加上

use AppEntityProducteur;

到你的DashboardController.php文件

Symfony 4.4 LTS版本有完全相同的问题。我通过将我的项目升级到Symfony 5.2来解决它。它似乎不再与4兼容。

当我有时间的时候,我会尝试创造一个可重复的问题。希望也能修复。

控制器服务需要标记为ea.crud_controllerea.dashboard_controller。或者更好的是,让easyadmin为您配置它们:

检查在Resources/config/services.xml中是否默认设置了autoconfigure="true":

<services>
<defaults autowire="true" autoconfigure="false" ...>
...

或者加上:

<services>
...
<prototype namespace="AppBundleControllerAdmin"
resource="../../Controller/Admin"
autoconfigure="true">
</prototype>

你可以检查标签是否添加得很好:

php bin/console debug:container --tag=ea.crud_controller

最新更新