Prestashop 1.7.7.rc1模块管理控制器中FrameworkBundleAdminController的C



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

我在FrameworkBundleAdminController中遇到ClassNotFoundException

// 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: 'PrestashopModuleHtDoctrineControllerAdminQuotesController::indexAction'
_legacy_controller: 'AdminHtDoctrineQuote'
_legacy_link: 'AdminHtDoctrineQuote'
// src/Controller/Admin/QuotesController.php
<?php
namespace PrestashopModuleHtDoctrineControllerAdmin;
use PrestashopBundleControllerAdminFrameworkBundleAdminController;
use SymfonyComponentHttpFoundationResponse;
class QuotesController extends FrameworkBundleAdminController
{
public function indexAction(): Response
{
return $this->render('@Modules/ht_doctrine/views/templates/admin/index.html.twig');
}
}

composer.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 "PrestashopBundleControllerAdmin".
Did you forget a "use" statement for "PrestaShopBundleControllerAdminFrameworkBundleAdminController"?

ClassNotFoundException在模块/ht_doctrine/src/Controller/AdminQuotesController.php(第7行(中

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

如果我清除了缓存,那没关系,但只要一次尝试。。在我再次遇到这个错误之后。你知道我错过了什么吗?在项目的根目录中,我没有执行任何composer操作。我不太理解模块的composer.json文件和主composer.jsp文件是如何相互作用的。

谢谢你的想法!

问题来自我的命名空间中忘记的大写字母(PrestaShop(。。。

use PrestaShopBundleControllerAdminFrameworkBundleAdminController;

而不是坏的:use PrestashopBundleControllerAdminFrameworkBundleAdminController;

最新更新