I have already written a snippet and can successfully create a new document. But unfortunately I have the problem after saving that the alias of the doc is empty in the cache. In particular I mean, the generated link to this doc is without the alias eg. www.some-domain.org/parentdoc/ and here should be the alias of the doc, but isn’t So as a result the page is not callable via the friendly URL. But when I take a look on the alias in the manger it’s there. It’s just a ,matter of caching I guess. As soon as I delete the cache everything works fine and the document is accessible via the alias (friendly URL).
However, there is one thing to mention in my code. Using Formit (in the frontend) a form is submitted and based on this the snippet creates a document. To avoid duplicate aliases, I use a generated uniqid.
So far so good, here is my code:
$doc = $modx->newObject('modDocument'); $doc->set('parent', $ParentID); $doc->set('pagetitle', $Pagetitle); //generate unique id for page alias $prefix = 'inserat-'; $Alias = uniqid($prefix); //example of Alias: inserat-60154384e5de7 $doc->set('alias', $Alias); $doc->set('template', $TemplateID); $doc->set('published', $Published); $doc->set('hidemenu', $HideMenu); $doc->set('cacheable', $Cacheable); $doc->setContent($Content ); $doc->save(); $docID = $doc->get('id'); // after that line some TV gets filled in with $tv->setValue($docID, 'some text fot the tv'); $tv->save();
Actually I would be super happy with this snippet, except for the problem with the cache. As a quick fix, I clear the entire cache every time with the snippet (CacheClear) from Bobray. I just use it as a hook in the formit call.
Am I doing something wrong when creating the doc in the snippet? If not, can I remove only this
document once from the cache? Always clearing the entire cache is not a good solution in the long run.
Thanks to all!