API MODX Создание нового ресурса

Вариант 1 - API

PHP:

// Засекаем время выполнения
$t1 = microtime(true);

$object = $modx->newObject('modResource');
$object->set('pagetitle', 'TestPage'); // Простой заголовок
$object->set('alias', 'testpage'); // Задаём алиас
$object->set('parent', '0'); // Под какого родителя поместить
$object->set('description', "I'm new resource");
$object->setContent('This will be the content of the new resource.');
$object->save();

// Выводим затраченное время
$t2 = microtime(true);
print "Time: ".($t2-$t1);

Вариант 2 - через процессоры

PHP:

// Засекаем время выполнения
$t1 = microtime(true);

$response = $modx->runProcessor('resource/create', array(
    'parent' => 1,
    'pagetitle' => 'New TestPage',
    'alias' => 'newtestpage',
    'description' => "I'm new resource",
    'content' => 'This will be the content of the new resource.'
));

if($response->isError()){
    print "Произошла ошибка". $response->getMessage();
}
else{
    $object = $response->getObject();
    print "\n";
    print "Был создан документ с ID {$object['id']}";
}

// Выводим затраченное время
$t2 = microtime(true);
print "Time: ".($t2-$t1);