Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Magento 2-安装程序上不存在类:di:compile_Php_Magento_Namespaces_Magento2 - Fatal编程技术网

Php Magento 2-安装程序上不存在类:di:compile

Php Magento 2-安装程序上不存在类:di:compile,php,magento,namespaces,magento2,Php,Magento,Namespaces,Magento2,我对Magento 2有些问题。我已经制作了自己的模块,看起来工作正常,但是当我安装模块并使php bin/magento setup:di:compile时,出现以下错误: [ReflectionException]类\MyInstaller不存在 它由setup/src/Magento/setup/Module/PhpScanner.php抛出 MyInstaller类存在,但是我更改了类文件的路径。最初有path/my libraries/MyInstaller.php,但当我在本地测试它

我对Magento 2有些问题。我已经制作了自己的模块,看起来工作正常,但是当我安装模块并使php bin/magento setup:di:compile时,出现以下错误:

[ReflectionException]类\MyInstaller不存在

它由setup/src/Magento/setup/Module/PhpScanner.php抛出

MyInstaller类存在,但是我更改了类文件的路径。最初有path/my libraries/MyInstaller.php,但当我在本地测试它时,出现了如上所述的错误:

[ReflectionException]类\MyInstaller不存在

当我将文件夹名更改为mylibraries时,在localhost上工作正常。然而,当我在外部服务器上安装模块时,我有ReflectionException。当我将文件夹名称更改为原始名称“我的库”时,它不会显示。正如我所观察到的,Magento仍然在呼唤一条古老的道路。但是,我尝试运行Magento 2的新实例,但仍然出现此错误

我试图通过以下方式清除缓存:

bin/magento cache:clean
bin/magento cache:flush
我也尝试删除/var文件夹。启用模块后,我将执行以下操作:

php bin/magento setup:upgrade

你能告诉我,我怎样才能强制Magento使用文件的新路径?还是应该更改服务器上的一些缓存设置

我补充说,MyInstaller类中没有名称空间,因为我在其他模块中使用相同的文件。但是,我认为如果在localhost上没有错误,就没有必要使用它们

有一个MyInstaller类代码:

<?php

if (!class_exists('MyInstaller', false)) {
class MyInstaller implements MyInterface
{
    private $translations;
    private $sliderEnabled = true;
    private $pages = array();

    public function __construct($sliderEnabled = true, array $translations = array())
    {
        $this->sliderEnabled = $sliderEnabled;
        $this->setTranslations($translations);
    }

    public function setTranslations(array $translations = array())
    {
        $this->translations = $translations;

    }

    public function addPages(array $pages = array())
    {
        $this->pages = array_values($pages);
    }

    public function renderInstallerSteps()
    {
        if (!$this->sliderEnabled || empty($this->pages) || !is_array($this->pages)) {
            return '';
        }

        $requirements = $this->checkRequirements();
        $params = array(
            'requirements' => $requirements,
            'translations' => $this->translations
        );
        $maxSteps = 0;
        $data = array(
            'steps' => array()
        );
        foreach ($this->pages as $page) {
            $page = (int)$page;
            if ($page > 0) {
                $step = $this->loadStep($page, $params);
                $data['steps'][$page] = $step;
                $maxSteps++;
            }
        }

        if ($maxSteps === 0) {
            return '';
        }
        $data['maxSteps'] = $maxSteps;

        return $this->loadTemplate('installer', $data);
    }

    private function loadStep($number, $params = null)
    {
        $step = $this->loadTemplate('step' . $number, $params);
        $step = $this->removeNewLines($step);
        return $step;
    }

    private function removeNewLines($string)
    {
        return trim(str_replace(PHP_EOL, ' ', $string));
    }

    private function loadTemplate($view, $data = null)
    {
        extract(array("content" => $data));
        ob_start();
        $viewFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'theme' . DIRECTORY_SEPARATOR . "$view.tpl.php";

        if (file_exists($viewFile)) {
            include $viewFile;
        } else {
            throw new Exception('View not exist in ' . get_class($this));
        }
        $content = ob_get_clean();
        return $content;
    }

    private function checkRequirements()
    {
        $data = array(
            'php' => array(
                'test' => (version_compare(PHP_VERSION, '5.2.0') > 0),
                'label' => $this->translations['php_version']
            ),
            'curl' => array(
                'test' => function_exists('curl_version'),
                'label' => $this->translations['curl_enabled']
            ),
            'soap' => array(
                'test' => class_exists('SoapClient'),
                'label' => $this->translations['soap_enabled']
            )
        );
        return $data;
    }
}
}


抱歉,如果描述混乱,这是我在这里的第一篇文章。

Magento2依赖于名称空间来分离和定位模块和类

所有文件都需要声明的命名空间,如下所示:

<?php
    namespace Vendor\MyModule\Setup;

    class MyInstaller implements ... {}
编辑-看到评论后


还要检查是否区分大小写-UNIX系统将此文件和此文件视为两个独立的文件,而Windows将其视为一个文件。

Magento2依赖名称空间来分离和定位模块和类

所有文件都需要声明的命名空间,如下所示:

<?php
    namespace Vendor\MyModule\Setup;

    class MyInstaller implements ... {}
编辑-看到评论后


还要检查区分大小写-UNIX系统将此文件和此文件视为两个单独的文件,而Windows将其视为一个文件。

您需要在Magento 2中使用名称空间。。。这可能就是为什么找不到它的原因。我考虑过这一点,但当我将文件夹名称更改为原始名称时,没有任何错误,即“我的库”没有名称空间。此外,它在当地也起作用。可能是其他原因吗?您的本地环境与您的生产/开发环境不同吗?e、 g.本地windows,开发linux?如果是这样,windows是不区分大小写的,所以这与此相同,而在linux上,这将是两个不同的文件。非常感谢您的建议。这是一个区分大小写的问题,我将文件夹名称更改为MyLibraries,在本地和生产环境中都可以正常工作。为您更新了我的答案:您需要在Magento 2中使用名称空间。。。这可能就是为什么找不到它的原因。我考虑过这一点,但当我将文件夹名称更改为原始名称时,没有任何错误,即“我的库”没有名称空间。此外,它在当地也起作用。可能是其他原因吗?您的本地环境与您的生产/开发环境不同吗?e、 g.本地windows,开发linux?如果是这样,windows是不区分大小写的,所以这与此相同,而在linux上,这将是两个不同的文件。非常感谢您的建议。这是区分大小写的问题,我将文件夹名称更改为MyLibraries,在本地和生产环境中都可以正常工作。为您更新了我的答案: