We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27449
    • 211 Posts
    Now I have other error huh
    Fatal error: Class ’modResource’ not found in core\model\modx\moddocument.class.php on line 14


    I have this code:

    require_once ’../../../config.core.php’;
    include_once MODX_CORE_PATH . ’model/modx/modx.class.php’;
    $modx= new modX();
    $doc = $modx->newObject(’modDocument’);

    $doc->set(’parent’,2);
    $doc->set(’alias’,$_POST[’title’]);
    $doc->set(’pagetitle’,$_POST[’title’]);
    $doc->set(’template’,2); // Id of the template
    $doc->set(’published’,1);
    $doc->set(’cacheable’,0);
    $doc->set(’hidemenu’,1);

    $doc->set(’title’,$_POST[’title’]);
    $doc->set(’data’,$_POST[’date’]);
    $doc->set(’small_description’,$_POST[’small_description’]);
    $doc->set(’description’,$_POST[’description’]);



    $doc->save();
      • 27449
      • 211 Posts
      Sorry.... but i’m new on the revolution modx..

      I have the last problem solved, but now I don’t know how add value to the Tv’s

      I create the template and the tv’s on the modx and now I want create automaticaly the document with the values of the tv’s

      On the last version of the modx I used the function

      $modx->SetTV(’title’,$_POST[’title’]);

      And now how I do?
        • 1778
        • 659 Posts
        Hello
        Bob has already give you the way to do that in post above...

        <?php
        $resource = $modx->newObject(('modDocument', array('name'=>'MyNewDoc'));
        $resource->save();
        
        $resource = $modx->getObject(('modDocument', array('name'=>'MyNewDoc'));
        $id = $resource->get('id');
        
        $tv = $modx->getObject('modTemplateVar',array('name'=>'MyTv')); // here you get the TV
        
        $tv->setValue($id,'value'); // here you set the tv value
        

          • 27449
          • 211 Posts
          Sorry but I don’t understand...

          Then for I create a new document and add values to the Tv’s I need this code:

          $doc = $modx->newObject(’modDocument’);

          $doc->set(’parent’,2);
          $doc->set(’alias’,$_POST[’title’]);
          $doc->set(’pagetitle’,$_POST[’title’]);
          $doc->set(’template’,2); // Id of the template
          $doc->set(’published’,1);
          $doc->set(’cacheable’,0);
          $doc->set(’hidemenu’,1);
          $doc->save();

          $idDoc = $doc->get(’id’);

          $resource = $modx->getObject(’modDocument’, $idDoc);
          $id = $resource->get(’id’);

          $tv = $modx->getObject(’modTemplateVar’,array(’name’=>’title’)); // here you get the TV
          $tv->setValue($id,$_POST[’title’]); // here you set the tv value

          $tv = $modx->getObject(’modTemplateVar’,array(’name’=>’data’)); // here you get the TV
          $tv->setValue($id,$_POST[’date’]); // here you set the tv value



          but I don’t get the values in the Tv’s huh

          What’s wrong?
            • 1778
            • 659 Posts
            Hi again

            Reading you code I understand you have a TV named ’title’ and another one named ’data’ is this right ?

            If yes, it is possible that using "title" as name for a TV was not a good idea... I’m not really sure of that but I remember I encountered some issues due to bad choice in naming elements. To prevent that I avoid all names that can be confused with "reserved" ones... (like "title") or I prefix them with something of my own like ’myTitle’ something I’m pretty sure is not used by the system...

            Hope this helps
            Cheers
              • 27449
              • 211 Posts
              Thanks I didn’t know that

              But apart of that the code it’s correct?
              I ask you because I don’t get the value on the tv’s
                • 1778
                • 659 Posts
                yep it seems to be correct ... But I’m not a guru ... Maybe there is something wrong that I don’t see
                Cheers
                  • 4172
                  • 5,888 Posts
                  see my example I linked above. There it is done like that:

                  <?php
                  
                  $doc = $modx->newObject('modDocument');
                  
                  $doc->set('parent',2);
                  $doc->set('alias',$_POST['title']);
                  $doc->set('pagetitle',$_POST['title']);
                  $doc->set('template',2); // Id of the template
                  $doc->set('published',1);
                  $doc->set('cacheable',0);
                  $doc->set('hidemenu',1);
                  $doc->save();
                  
                  $fields['title']=$_POST['title'];
                  $fields['data']=$_POST['date'];
                       
                  foreach ($fields as $field=>$value)
                  {
                      if ($tv = $modx->getObject('modTemplateVar', array ('name'=>$field)))
                      {
                          $tv->setValue($doc->get('id'), $value);
                          $tv->save();
                      }
                  }
                  
                  return true;


                  you forgot:
                  $tv->save();


                  for each TV
                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!
                    • 27449
                    • 211 Posts
                    Thanks a lot grin

                    Finally it’s working
                      • 3749
                      • 24,544 Posts
                      Quote from: sjscosta at Oct 08, 2010, 03:46 AM

                      Thanks a lot grin

                      Finally it’s working

                      Sorry -- my fault for leaving $tv->save() out of my example.

                      Glad you got it working. smiley
                        Did I help you? Buy me a beer
                        Get my Book: MODX:The Official Guide
                        MODX info for everyone: http://bobsguides.com/modx.html
                        My MODX Extras
                        Bob's Guides is now hosted at A2 MODX Hosting