Hello,
I create a module in the modx that work perfectly. But now, I want that when I put there information, these information stay in the database, create one document automaticaly with the information that I put in the module.
That is possible, when us put information in the modulo create a document in the modx with this information?
You need an field-array for the document-values and for the TV-values, then you can use this function or you can use the docmanager-class:
http://modxcms.com/Docmanager-881.html
function insertdoc($doc_array, $tv_array)
{ global $modx;
$doctable = $modx->getFullTableName('site_content');
$tvtable = $modx->getFullTableName('site_tmplvar_contentvalues');
//Todo: checkbox to allow invokeevents
$modx->invokeEvent('OnBeforeDocFormSave', array('mode'=>'new'));
$modx->db->insert($doc_array, $doctable);
$id = $modx->db->getInsertId();
//---------insert TVs----------------------
foreach ($tv_array as $key=>$value)
{
$insert_array = array (
'tmplvarid'=>$key,
'value'=>$value,
'contentid'=>$id);
$modx->db->insert($insert_array, $tvtable);
}
$modx->invokeEvent('OnDocFormSave', array('mode'=>'new', 'id'=>$id));
return $id;
}
You could do what Brun17 says, but I think it is better to create a snippet which reads the data from the database and outputs that.
How would you change or delete the document automaticly when you edit or remove a item in the module?
with regards,
Ronald Lokers
'Front-end developer' @
h2o Media