Magento 2:找不到类'ObjectManager'

时间:2017-11-17 13:36:07

标签: magento2

我有一个cron要运行以添加到数据库中的给定表,这里是cron

<?php
    require_once 'Price.php';
    $cron=new \Managys\Pricing\Price();
    $cronGo = $cron->GetNewproduct();

&GT;

Class Price.php:

<?php
namespace Managys\Pricing;
use Magento\Framework\App\ObjectManager;
class Price
 {
    function GetNewproduct()
   {
    $objectManager = ObjectManager::getInstance();
    $resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
    $connection = $resource->getConnection();
    $tableName = $resource->getTableName('mp_new_products');
....
}

为了调用这个cron我有一个错误 enter image description here

1 个答案:

答案 0 :(得分:0)

首先:NEVER use ObjectManager

回到你的问题,改变

use Magento\Framework\App\ObjectManager;

use \Magento\Framework\App\ObjectManager;

原因:您不在Magento命名空间下。您应该在任何类声明之前添加斜杠(\)以使用核心函数。