首页>Magento>source

基于这个非常相似问题的答案: 如何在Mawnto 2中引导Magento 2 test.php脚本?,特别是https://magento.stackexchange.com/a/76382,< / p>

当我跑 php abstract.php时 ,我收到以下错误:

PHP Fatal error: Interface 'Magento\Framework\AppInterface' not found in /var/www/html/scripts/abstract.php on line 14

这可能是非常基本的,请原谅我,但是有人能指出我正确的方向吗?

scripts/abstract.php ,从上面的链接看起来像

<?php
use \Magento\Framework\AppInterface as AppInterface;
use \Magento\Framework\App\Http as Http;
use Magento\Framework\ObjectManager\ConfigLoaderInterface;
use Magento\Framework\App\Request\Http as RequestHttp;
use Magento\Framework\App\Response\Http as ResponseHttp;
use Magento\Framework\Event;
use Magento\Framework\Filesystem;
use Magento\Framework\App\AreaList as AreaList;
use Magento\Framework\App\State as State;
abstract class AbstractApp implements AppInterface
{
    public function __construct(
        \Magento\Framework\ObjectManagerInterface $objectManager,
        Event\Manager $eventManager,
        AreaList $areaList,
        RequestHttp $request,
        ResponseHttp $response,
        ConfigLoaderInterface $configLoader,
        State $state,
        Filesystem $filesystem,
        \Magento\Framework\Registry $registry
    ) {
        $this->_objectManager = $objectManager;
        $this->_eventManager = $eventManager;
        $this->_areaList = $areaList;
        $this->_request = $request;
        $this->_response = $response;
        $this->_configLoader = $configLoader;
        $this->_state = $state;
        $this->_filesystem = $filesystem;
        $this->registry = $registry;
    }
    public function launch()
    {
        $this->run();
        return $this->_response;
    }
    abstract public function run();
    public function catchException(\Magento\Framework\App\Bootstrap $bootstrap, \Exception $exception)
    {
        return false;
    }
}
最新回答
  • 2019-8-13
    1 #

    abstract.php   不应该自己运行.该文件中没有任何内容可以加载Magento或其自动加载器,并且该类被声明为 abstract   (你不能直接使用它).它失败了,因为有一个类名PHP本身不知道该怎么做。

    在您链接的答案中,有第二个脚本 scripts/delete-category.php   演示如何实际使用它.您需要创建第二个文件,然后运行该脚本( php scripts/delete-category.php ).你可以改变这个 run()的名字和内容   方法以满足您的需求。

    这应该让你起步并运行。

    话虽如此,我只是提出了另一种方法来解决这个问题.它比您正在尝试的独立文件(您需要一个实际的模块)更复杂,但它对Magento来说更合适.请参阅:https://magento.stackexchange.com/a/102901/1905

  • email templates:在Magento232中:邮件发送设置: - 它是通过localhost还是Not?
  • 如何在magento2中创建销售订单等自定义网格?