无法创建新资源。在 null 上调用成员函数 newObject()

Cant create new Resource. Call to a member function newObject() on null

我需要以编程方式创建资源,但出现错误。 我有一个父 Uki(4),我可以手动创建资源。 当我使用 $data 数组的 运行 函数来创建资源时 - 它在 $modx->newObject('modResouce');

上给出 null

我试过使用 $modx->runProcessor('resource/create', $createresource); - 它也给出了 null 错误。

require_once '/opt/lampp/htdocs/modx/config.core.php';
require_once( MODX_CORE_PATH . 'model/modx/modx.class.php');
$modx = new modX();
$modx->initialize('web');
//Подгрузка сервисов модекса

define('MODX_API_MODE', true);
$modx->getService('error','error.modError');
$modx->lexicon->load('minishop2:default');
$modx->lexicon->load('minishop2:manager');
$miniShop2 = $modx->getService('minishop2','miniShop2',
$modx->getOption('minishop2.core_path',null,
$modx->getOption('core_path').'components/minishop2/').'model/minishop2/', array());


function productAddItemBD($data)
{     


$doc = $modx->newObject('modResouce');    //81 line =====
    $doc->set('parent', '0');
    $doc->set('pagetitle', $data['pagetitle']);
    $doc->set('alias', $data['alias']);
    $doc->save();



    $modifications = $modx->call('msopModification', 'saveProductModification', array(&$modx, $doc->id, $data['modprices']));
    $response = 
            $modx->runProcessor('gallery/upload', array('id' => $doc->id, 
                'name' => $data['title'], 'file' => $data['img']), 
                array('processors_path' => MODX_CORE_PATH . 'components/minishop2/processors/mgr/'));
    if ($response->isError()) {
        throw new Exception(get_error_string($response,' Site: create modification or gallery item'));
    }
$item_created++;
  return true;

}

给出错误:

    Fatal error: Uncaught Error: Call to a member function newObject() on null in 
    /opt/lampp/htdocs/modx/core/cache/includes/elements/modsnippet/2.include.cache.php:81 Stack trace: #0   
      /opt/lampp/htdocs/modx/core/cache/includes/elements/modsnippet/2.include.cache.php(56): productAddItemBD(Array) #1 
/opt/lampp/htdocs/modx/core/cache/includes/elements/modsnippet/2.include.cache.php(41): goThroughArrayOFPRODUCTS(Array) #2 
    /opt/lampp/htdocs/modx/core/model/modx/modscript.class.php(76): include('/opt/lampp/htdo...') #3     
    /opt/lampp/htdocs/modx/core/model/modx/modparser.class.php(537): modScript->process(NULL) #4 
    /opt/lampp/htdocs/modx/core/components/pdotools/model/pdotools/pdoparser.class.php(273): modParser->processTag(Array, false) #5 
    /opt/lampp/htdocs/modx/core/model/modx/modparser.class.php(251): pdoParser->processTag(Array, false) #6 
    /opt/lampp/htdocs/modx/core/components/pdotools/model/pdotools/pdoparser.class.php(65): modParser->processElementTags('[[]]', '<!doctype html>...', false, false, '[[', ']]', Array, 8) #7 /opt/lampp in 
    /opt/lampp/htdocs/modx/core/cache/includes/elements/modsnippet/2.include.cache.php on line 81

函数中不存在变量“$modx”。

在函数内声明变量,或使用"global $modx;"

$modx->newObject('modResouce'); "modResource" 中的 "r" 缺失。

对于 运行 进程,您的用户组必须具有正确的访问权限。我会附上截图 modx admin panel