hello,
I need to create a document programmatically in Revolution 2.1. I'd like to set a title and assign a template.
How can I do that via Modx Apis?
Thanks for your time and help.
[ed. note: eclipseTalk last edited this post 14 years, 10 months ago.]
-
☆ A M B ☆
- 24,524 Posts
-
☆ A M B ☆
- 24,524 Posts
As has been said long ago, we stand upon the shoulders of giants
I think this method is preferred now:
<?php
$title = 'MyPage';
$pageAlias = 'my-page';
$templateId = 2;
$fields = array(
'pagetitle' => $title,
'template' => $templateId,
'alias' => $pageAlias,
/* other fields here as necessary. System defaults will be used if empty */
};
/* create and save new resource */
$response = $this->modx->runProcessor('resource/create', $fields);
/* optional error handling */
if ($response->isError()) {
if ($response->hasFieldErrors()) {
$fieldErrors = $response->getAllErrors();
$errorMessage = implode("\n", $fieldErrors);
} else {
$errorMessage = 'An error occurred: ' . $response->getMessage();
}
return $errorMessage;
} else {
/* optional - in case you want the ID of the new resource (e.g., for makeUrl() ) */
$object = $response->getObject();
$resourceId = $object['id'];
}
[ed. note: BobRay last edited this post 14 years, 10 months ago.]