We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17016
    • 138 Posts
    Ok, now it works. I didn´t see that runSnippet was just an example and that it has to be changed into "runProcessor" like you already changed in the script above.

    Perfect! Thanks a lot for your help. As soon as your MODx-Team changed the links on http://modx.com/community/wall-of-fame/ to direct links to the donator (at the moment these are still redirects what is not very good of SEO-reasons grin) we will like to do our next donations smiley)))

    Thanks a lot again!
    Letti

      • 3749
      • 24,544 Posts
      That would be great. smiley

      You can also donate to Bob’s Guides here: http://bobsguides.com/support-this-site.html
        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
        • 17016
        • 138 Posts
        Ok, if "they" don´t manage to change the Link-Structure in the next time I will donate on your site smiley

        Btw: Can you tell me how I can modify the values of a TV of an existing resource. I know how to read a TV by $doc->getTVValue but I don´t know how to change the value of an existing TV of a resource. Maybe by a call like this $modx->runProcessor(’resource/update’, $fields); The goal is to publish the site for the uploading-process to the Mailing-Tool and unpublish the resource afterwards again...
          • 3749
          • 24,544 Posts
          You can’t set it through the resource. This is the easiest way:

          <?php
          $docId = ##; // set to the ID of the resource
          $tvId = ##'; .. set to the ID of the TV
          
          $tv = $modx->getObject('modTemplateVar',  $tvId);
          
          $tv->setValue($docId, 'Value');
          $tv->save();
          


            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
            • 17016
            • 138 Posts
            Perfect!

            Btw: While creating a "modDocument" works very well now, there is a problem on creating the symlink (the symlink is going to be a child of the resource created before, using a different template):

            $fieldstxt = array();
            $fieldstxt['pagetitle'] = $mailingname."-txt";
            $fieldstxt['alias'] = $mailingname."-txt";
            $fieldstxt['template'] = '52';
            $fieldstxt['parent'] = $idofnewresource;
            
            $response = $modx->runProcessor('symlink/create', $fieldstxt);


            It is resulting in the same error on making the error-check as before:
            Fatal error: Call to a member function isError() on a non-object in line:
            if ($response->isError()) {

            Is there anything what has to be changed compared to the modDocument-creation?
              • 3749
              • 24,544 Posts
              It’s possible that the Symlink create processor is not fully implemented. There was a bug like that in the create processor that’s been fixed, but it may still exist in the Symlink processor.

              You can always create the symlink yourself the old-fashioned way

              $fields = array();
              
              $fields['pagetitle'] = 'MyPage';
              $fields['parent'] = $parentId;
              $fields['content'] = $targetId;
              //etc.
              
              $resource = $modx->newObject('modSymlink', $fields);
              $resource->save();
              


              And please report the bug you found, so it can be fixed.

                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
                • 17016
                • 138 Posts
                As proposed I meanwhile created the symlink-resource in this "old-fashioned" way:
                $fields['content'] = $targetId;
                //etc.
                
                $resource = $modx->newObject('modSymlink', $fields);
                $resource->save();

                The disadvantage is that applying this method it is not possible to use this to get the id of the new symlink-resource:

                $object = $response->getObject();
                $idofnewresource = $object['id'];

                Is there maybe another way to get the id when using the old way for creating a symlink-resource?

                Letti
                  • 3749
                  • 24,544 Posts
                  If the DB engine is MySQL, you should be able to use

                  $id = last_insert_id();
                  
                  // or
                  
                  $id = mysql_insert_id();
                  
                  
                    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
                    • 17016
                    • 138 Posts
                    Unfortunately it is not working. The first results in this:

                    Call to undefined function last_insert_id()


                    And the second one does not give back anything.

                    To get the id seems to be not very easy...
                      • 3749
                      • 24,544 Posts
                      The second one should definitely work as long as you place it after the save().
                        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