Created
July 27, 2014 09:22
-
-
Save evilj0e/b4df34ca6dc24dc5324b to your computer and use it in GitHub Desktop.
Snippet for MODx Revolution to generate documents with your data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* AutoGenerator Snippet to generate documents with your data | |
* | |
* @version 0.1 | |
* @author Anton Konev (devdigital.ru) | |
* | |
* @example [[AutoGenerator? &parentid=`0`]] | |
* | |
* @var parent of documents $parentid | |
* @var document's data $data | |
* | |
*/ | |
/* checking data array*/ | |
isset( $data ) ? | |
$data : | |
$data = array( | |
'<p>Text</p>', | |
'<p>Text</p>', | |
); | |
foreach ($data as $index => $value) { | |
$product = $modx->newObject( 'modResource' ); | |
$product->fromArray( | |
array( | |
'pagetitle' => 5000+$index, | |
'alias' => 5000+$index, | |
'longtitle' => '', | |
'parent' => $parentid, | |
'published' => 1, | |
'hidemenu' => 0, | |
'isfolder' => 1, | |
'searchable' => 1, | |
'template' => 12, | |
'content' => $value | |
) | |
); | |
$product->save(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment