We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19680
    • 19 Posts
    Сделал по примеру добавление документа по данным формы
    <?php
    function createNewResource( &$fields ){
        
        global $modx;
        $values = array();
            
        $values['pagetitle'] = $modx->db->escape($fields['title']);
        $values['longtitle'] = '';
        $values['description'] = '';
        $values['alias'] = '';
        $values['published'] = 0; //0 - if you want the document to be created unpublished
        $values['parent'] = 2; //id of the container for the the new document
        $values['introtext'] = '';
        $values['content'] = $modx->db->escape($fields['content']);
        $values['template'] = 3; //the template of your new document
        $values['searchable'] = 1;
        $values['cacheable'] = 1;
        $values['createdby'] = 1; //this is not the web user ID. Change it to an existing manager id
        $values['createdon '] = time();
        $values['editedby'] = 1; //this is not the web user ID. Change it to an existing manager id
        $values['editedon '] = time();
        //you can find more document properties by browsing the modx_site_content table
            
        //insert the new document. In case you need the id of the new document use the  $newId variable
        $newId = $modx->db->insert( $values, $modx->getFullTableName('site_content') );
    
    
    $customValues = array();
    
    $customValues['tmplvarid'] = 1;//ID TV 
    $customValues['contentid'] = $newId;
    $customValues['value'] = $modx->db->escape($fields['email']);   
    
    
    $modx->db->insert( $customValues, $modx->getFullTableName('site_tmplvar_contentvalues') );
        //clear the cache. in case you use Ditto to display the new document
        clearCache();
            
        return true;
    }
    
    function clearCache() {
        include_once "manager/processors/cache_sync.class.processor.php";
        $sync = new synccache();
        $sync->setCachepath("assets/cache/");
        $sync->setReport(false);
        $sync->emptyCache();
    }
    ?>

    При добавлении TV например
    $customValues['tmplvarid'] = 2;//ID TV 
    $customValues['contentid'] = $newId;
    $customValues['value'] = $modx->db->escape($fields['phone']);

    В документе сохраняется только последний TV-параметр.

    Вопрос в следующем. Как сделать так что бы сохранялись несколько TV-параметров?

    Очень надеюсь на вашу помощь!
      • 5666
      • 12 Posts
      Каждый TV параметр — это отдельная запись в таблице site_tmplvar_contentvalues, т.е. если TV параметра два то и вызовов $modx->db->insert( $customValues, $modx->getFullTableName(’site_tmplvar_contentvalues’) ); тоже должно быть два.

      Можно воспользоваться библиотекой Docmanager: http://modx.com/extras/package/docmanager?version=4d556ac7b2b083396d0001fa