Quote from: Bruno17 at Oct 25, 2010, 03:45 PM
to get the id, you need to save the resource
then you can get the id with
after that and if you want to have the alias is the id you can set your alias with
and save your resource again
That worked, but then stopped working? It is not saving with a URL it is weird. So when I save it and the go to the page that is displaying them, there is no URL. But when I clear the cache in the manager, then view the page they are displayed on, it works. Here is the formit2resource snippet:
<?php
$doc = $modx->getObject(’modResource’,array(’id’=>$hook->getValue(’resource_id’)));
if (empty($doc)){
$doc = $modx->newObject(’modResource’);
$doc->set(’createdby’, $modx->user->get(’id’));
}
else{
$doc->set(’editedby’, $modx->user->get(’id’));
}
$allFormFields = $hook->getValues();
foreach ($allFormFields as $field=>$value)
{
if ($field !== ’spam’ && $field !== ’resource_id’){
$doc->set($field, $value);
}
}
$doc->set(’template’, ’2’); // Use NominationTemplate
$doc->set(’published’,’1’); // Set resource to be published.
$doc->save();
$id=$doc->get(’id’);
$doc->set(’alias’, $id);
$doc->save();
foreach ($allFormFields as $field=>$value)
{
if ($tv = $modx->getObject(’modTemplateVar’, array (’name’=>$field)))
{
/* handles checkboxes & multiple selects elements */
if (is_array($value)) {
$featureInsert = array();
while (list($featureValue, $featureItem) = each($value)) {
$featureInsert[count($featureInsert)] = $featureItem;
}
$value = implode(’||’,$featureInsert);
}
$tv->setValue($doc->get(’id’), $value);
$tv->save();
}
}
return true;
?>