正如你可以看到在下面的代码,当我试图删除我的类别.它的给予我以下错误:
无法自动连接“App\Controller\AdminController::deleteCategory()"的参数$category:它引用类“App\Entity\Category”,但不存在此类服务。
这是我在AdminController.php中创建的函数代码:
<?php
namespace App\Controller;
使用App\Utils\CategoryTreeAdminList;
使用Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
使用Symfony\Component\HttpFoundation\Response;
使用Symfony\Component\Routing\Annotation\Route;
使用App\Entity\Category;
[Route('/admin')]
类AdminController扩展AbstractController {
#[Route('/delete-category/{id}', name: 'delete_category')]
public function deleteCategory(Category $category): Response
{
$entityManager = $this->getDoctrine()->getManager();
$entityManager->remove($category);
$entityManager->flush();
return $this->redirectToRoute('categories');
}
}
下面是我提到categoryList的代码:
<?php
命名空间App\Utils;
使用App\Utils\AbstractClasses\CategoryTreeAbstract;
类CategoryTreeAdminList扩展CategoryTreeAbstract {
public $html_1 = '<ul class="fa-ul text-left">';
public $html_2 = '<li><i class="fa-li fa fa-arrow-right"></i> ';
public $html_3 = '<a href="';
public $html_4 = '">';
public $html_5 = '</a> <a onclick="return confirm(\'Are you sure?\');" href="';
public $html_6 = '">';
public $html_7 = '</a>';
public $html_8 = '</li>';
public $html_9 = '</ul>';
public function getCategoryList(array $categories_array)
{
$this->categorylist .= $this->html_1;
foreach ($categories_array as $value) {
$url_edit = $this->urlgenerator->generate('edit_category', ['id' => $value['id']]);
$url_delete = $this->urlgenerator->generate('delete_category', ['id' => $value['id']]);
$this->categorylist .= $this->html_2 . $value['name'] .
$this->html_3 . $url_edit . $this->html_4 . ' Edit' .
$this->html_5 . $url_delete . $this->html_6 . 'Delete' .
$this->html_7;
if (!empty($value['children'])) {
$this->getCategoryList($value['children']);
}
$this->categorylist .= $this->html_8;
}
$this->categorylist .= $this->html_9;
return $this->categorylist;
}
}
3条答案
按热度按时间zdwk9cvp1#
@ soul继续使用此代码.....您可以解决此错误,并让我知道是否已解决。
谢谢
vcirk6k62#
您需要运行以下命令:
composer require sensio/framework-extra-bundle
2ekbmq323#
如果你使用symfony >= 5.4,你不应该安装
sensio/framework-extra-bundle
,因为sensio/framework-extra-bundle
已经被放弃了。