I want to create a script to auto create and populate some resources. But I cant find the code to create a new resource / page from PHP.
Could anyone please guide me in the right direction?
Thanks
-
☆ A M B ☆
- 24,524 Posts
Scroll down to the "creating new objects" section
http://bobsguides.com/revolution-objects.html
Also see
http://rtfm.modx.com/xpdo/2.x/class-reference/xpdoobject/field-accessors/fromarray
$page = $modx->newObject('modResource');
$data = array(
'pagetitle' => 'My Page',
'description' => 'Why not?',
// ... etc...
);
$page->fromArray($data);
$page->save();
thurft, please don't double post.
I answered you here with an example that uses the processor.
https://forums.modx.com/thread/88209/how-to-create-a-new-page-document-using-php#dis-post-485474
Using newObject() will work fine (and it's easier), but calling the processor will fire the appropriate system events so plugins that are connected to Resource save events will execute. If it's just custom code for your site, it may not matter, but if it's something you might distribute, it should either call the processor, or fire the System Events itself with $modx->invokeEvent().