Skip to content

Instantly share code, notes, and snippets.

@em-piguet
Last active November 21, 2015 17:12
Show Gist options
  • Save em-piguet/b2857f378d1d9504581c to your computer and use it in GitHub Desktop.
Save em-piguet/b2857f378d1d9504581c to your computer and use it in GitHub Desktop.
Create MODX Resources with a Loop
<?php
/*
* CreateResource MODX API
* http://forums.modx.com/thread/82642/how-would-i-create-a-new-resource-via-the-api#dis-post-456111
*/
$i='';
for($i==0; $i<=100; $i++){
$fields = array(
'pagetitle' => 'c'.$i,
'parent' => 11,
'published' => 1,
'tvs' => true, // if you want to populate TV you need this
'alias' => 'c-'.$i,
'content' => 'content of resource c-'.$i ,
'tv1' => 'http://placehold.it/250x250', // set a value tv (need the TV id - tv1,tv2,etc..)
'template' => 2
);
$response = $modx->runProcessor('resource/create', $fields);
if ($response->isError()) {
return 'Oops!';
} else {
// Success!
echo 'Resource' .$i. ' Created !<br/>';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment