【问题标题】:Magento2 controller not found, auto-loading namespace using composer未找到 Magento2 控制器,使用 composer 自动加载命名空间
【发布时间】:2020-01-11 10:16:46
【问题描述】:

运行时出现 404 not found 错误 https://example.com/uicustomer/index/test 请帮忙!!

vendor\magento2-vendor-ui_customer\Controller\Index\Test.php

<?php
namespace Vendor\UiCustomer\Controller\Index;
class Test extends \Magento\Framework\App\Action\Action
{
protected $_pageFactory;

public function __construct(
    \Magento\Framework\App\Action\Context $context,
    \Magento\Framework\View\Result\PageFactory $pageFactory)
{
    $this->_pageFactory = $pageFactory;
    return parent::__construct($context);
}

public function execute()
{
    echo "Hello World";
    exit;
}
}

供应商\magento2-vendor-ui_customer\etc\module.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Vendor_UiCustomer" setup_version="1.1.3">
</module>
</config>

vendor\magento2-vendor-ui_customer\etc\frontend\routes.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etc/routes.xsd">
<router id="standard">
    <route frontName="uicustomer" id="uicustomer">
        <module name="Vendor_UiCustomer"/>
    </route>
</router>
</config>

供应商\magento2-vendor-ui_customer\composer.json

{
  "name": "vendor/magento2-vendor-ui_customer",
  "autoload": {
    "files": [
  "registration.php"
    ],
    "psr-4": {
      "Vendor\\UiCustomer\\": ""
    }
  }
}

供应商\magento2-vendor-ui_customer\registration.php

<?php
use \Magento\Framework\Component\ComponentRegistrar;
ComponentRegistrar::register(
ComponentRegistrar::MODULE,
'Vendor_UiCustomer',
__DIR__
);

【问题讨论】:

  • 我只是查看了 composer/autoload_psr4.php 它没有在这个文件中生成命名空间

标签: php composer-php magento2


【解决方案1】:

所以我通读了整个 Magento 2.3 文档,发现问题出在命名空间中的“UI”文本上。根据文件,这是不允许的。可能是一个错误。所以我不得不将 UICustomer 更改为 ExtCustomer 并解决了问题

{
"name": "vendor/magento2-vendor-ui_customer",
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
  "Vendor\\UiCustomer\\": ""
}
}
}

【讨论】:

    猜你喜欢
    • 2016-12-08
    • 2014-05-02
    • 2014-03-17
    • 2014-09-24
    • 1970-01-01
    • 2013-11-30
    • 1970-01-01
    • 2016-01-22
    • 1970-01-01
    相关资源
    最近更新 更多