首页 > 解决方案 > Prestashop 1.7.7.rc1 模块管理控制器中 FrameworkBundleAdminController 的 ClassNotFoundException

问题描述

我正在对 prestashop 1.7.7.0.rc1 进行一些测试,并尝试在模块上使用 Symfony 创建管理控制器。

我遇到了 ClassNotFoundExceptionFrameworkBundleAdminController

// ht_doctrine.php

declare(strict_types=1);

if (!defined('_PS_VERSION_')) {
    exit;
}
if (file_exists(__DIR__.'/vendor/autoload.php')) {
    require_once __DIR__.'/vendor/autoload.php';
}

class Ht_doctrine extends Module
{
    public function __construct()
    {
        $this->name = 'ht_doctrine';
        $this->author = 'Hugues';
        $this->version = '1.0.0';
        $this->ps_versions_compliancy = ['min' => '1.7.7', 'max' => _PS_VERSION_];
        $this->need_instance = 0;

        $this->bootstrap = true;

        parent::__construct();

        $this->displayName = $this->l('Exemple HW Doctrine');
        $this->description = $this->l('Demonstration des entités Doctrine');
    }

    public function install()
    {
        return parent::install()
            && $this->registerHook('displayHome');
    }
    public function uninstall()
    {
        return parent::uninstall();
    }
    public function getContent()
    {
        Tools::redirectAdmin(
            $this->context->link->getAdminLink('AdminHtDoctrineQuote')
        );
    }
    public function hookDisplayHome()
    {
        $this->smarty->assign(['quotes' => []]);
        return $this->fetch('module:ht_doctrine/views/templates/hooks/quotes.tpl');
    }
}
# config/routes.yml
htdoctrine_quote_index:
    path: /htdoctrine/quotes
    methods: [GET]
    defaults:
        _controller: 'Prestashop\Module\HtDoctrine\Controller\Admin\QuotesController::indexAction'
        _legacy_controller: 'AdminHtDoctrineQuote'
        _legacy_link: 'AdminHtDoctrineQuote'
// src/Controller/Admin/QuotesController.php
<?php
namespace Prestashop\Module\HtDoctrine\Controller\Admin;

use PrestashopBundle\Controller\Admin\FrameworkBundleAdminController;
use Symfony\Component\HttpFoundation\Response;

class QuotesController extends FrameworkBundleAdminController
{
    public function indexAction(): Response
    {
        return $this->render('@Modules/ht_doctrine/views/templates/admin/index.html.twig');
    }
}

作曲家.json:

{
  "name": "lhapaipai/htdoctrine",
  "autoload": {
    "psr-4": {
      "Prestashop\\Module\\HtDoctrine\\": "src/"
    }
  },
  "config": {
    "prepend-autoloader": false,
  },
  "type": "prestashop-module"
}

在我想使用这个模块之前,我写:

rm -rf var/cache/dev
cd modules/ht_doctrine
composer dump-autoload

我尝试导航到我的 conf 页面,没关系!但是如果我刷新页面,我会收到来自 Symfony 的错误消息。

Attempted to load class "FrameworkBundleAdminController" from namespace "PrestashopBundle\Controller\Admin".
Did you forget a "use" statement for "PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController"?

模块/ht_doctrine/src/Controller/Admin/QuotesController.php 中的 ClassNotFoundException(第 7 行)

    namespace Prestashop\Module\HtDoctrine\Controller\Admin;
    use PrestashopBundle\Controller\Admin\FrameworkBundleAdminController;
    use Symfony\Component\HttpFoundation\Response;
--> class QuotesController extends FrameworkBundleAdminController
    {
        public function indexAction(): Response
        {
            return $this->render('@Modules/ht_doctrine/views/templates/admin/index.html.twig');
        }

如果我清除缓存没关系,但试一试..在我再次遇到此错误之后。你知道我错过了什么吗?我没有composer在项目的根部执行任何操作。我不太明白模块的composer.json文件和主composer.json文件是如何交互的。

谢谢你的想法!

标签: phpsymfonyprestashop

解决方案


问题来自我的命名空间中一个被遗忘的大写字母(Presta S hop)......

use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController;

而不是坏的:use PrestashopBundle\Controller\Admin\FrameworkBundleAdminController;


推荐阅读