Php 类别Company\Module\Console\ImageImportConsole\Interceptor不存在
我正在创建一个自定义命令行,将图像从M1导入M2 我已经创建了一个命令,它工作正常。现在,我正试图将我的助手类调用到控制台中。但是得到了错误-Php 类别Company\Module\Console\ImageImportConsole\Interceptor不存在,php,command,magento2,Php,Command,Magento2,我正在创建一个自定义命令行,将图像从M1导入M2 我已经创建了一个命令,它工作正常。现在,我正试图将我的助手类调用到控制台中。但是得到了错误- In ClassReader.php line 24: Class Company\Module\Console\ImageImportConsole\Interceptor does not exist 下面是扩展命令类- <?php namespace Company\Module\Console; use Symfony\Componen
In ClassReader.php line 24:
Class Company\Module\Console\ImageImportConsole\Interceptor does not exist
下面是扩展命令类-
<?php
namespace Company\Module\Console;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
class ImageImportConsole extends Command
{
const PRODUCT_ID = 'productId'; // key of parameter
protected $helper;
public function __construct(
Company\Module\Helper\Data $helper
) {
$this->helper = $helper;
}
protected function configure(){
$options = [
new InputOption(
self::PRODUCT_ID, // the option name
'-id', // the shortcut
InputOption::VALUE_REQUIRED, // the option mode
'Optional Parameter. Product entity_id. It will start importing image from this id.' // the description
),
];
$this->setName('imageimporttool:start');
$this->setDescription('Image Import Tool');
$this->setDefinition($options);
parent::configure();
}
protected function execute(InputInterface $input, OutputInterface $output){
$id = $input->getOption(self::PRODUCT_ID);
// $helper = new Data();
$this->helper->test();
// if ($id) {
// // $output->writeln("Hi " . $id . ", Success!");
// } else {
// }
$output->writeln("Success");
}
}
删除vendor/
并运行composer安装
检查Company\Module\Console\ImageImportConsole\Interceptor
-它是否存在于您的项目中?也许您只是将这个类导入到其他地方,但它不存在
其他一切对我来说都正常。运行命令行:
php bin/magento setup:di:compile
php bin/magento c:f
最后,经过一些研究,我找到了一个解决方案
我们必须通过Magento\Framework\App\State
调用helper类
<?php
namespace Company\Module\Console;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Magento\Framework\App\State;
class ImageImportConsole extends Command
{
const PRODUCT_ID = 'productId'; // key of parameter
protected $helper;
public function __construct(
Company\Module\Helper\Data $helper,
State $state,
) {
$this->helper = $helper;
$this->state = $state;
}
protected function configure(){
$options = [
new InputOption(
self::PRODUCT_ID, // the option name
'-id', // the shortcut
InputOption::VALUE_REQUIRED, // the option mode
'Optional Parameter. Product entity_id. It will start importing image from this id.' // the description
),
];
$this->setName('imageimporttool:start');
$this->setDescription('Image Import Tool');
$this->setDefinition($options);
parent::configure();
}
protected function execute(InputInterface $input, OutputInterface $output){
$id = $input->getOption(self::PRODUCT_ID);
$this->helper->test();//this we start working
$output->writeln("Success");
}
}
我再次尝试安装composer。但同样的错误。