We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 38593
    • 129 Posts
    Is there an API or function within MODX to generate an array or a simple list of id numbers for published resources? The resultant array would be used in an external PHP scipt.

    If there is no existing way to do such, would someone be able to direct me to the appropriate table and columns within the extensive MODX database where this data is stored?

    This question has been answered by mrcycling. See the first response.

    [ed. note: mrcycling last edited this post 11 years ago.]
      Pedalers Bicycle Tours my website forged with MODX
      vandergraaf-M static website generator for MODX
      • 48532
      • 23 Posts
      Use the modResource object in combination with collection in a Snippet.

      $resources = $modx->getCollection('modResource', array('published'=>'1','deleted'=>'0'));
      foreach ($resources as $resource) {
         /* do something, e.g. save into another array */
      }


      If you want to select only the IDs column you should use a query.
      $query = $xpdo->newQuery('modResource');
      $query->select($xpdo->getSelectColumns('modResource','','',array('id','name')));
      $resources = $xpdo->getCollection('modResource',$query);
      foreach ($resources as $resource) {
         /* do something, e.g. save into another array */
      }
        • 38593
        • 129 Posts
        Thanks. I actually will be using the array/list outside of MODX (I modified my question a bit to clarify this).

        I am fetching completed webpages with the PHP script, then preforming some magic on them, before storing them elsewhere. Currently using a handbuilt array, but would like to automate that part.
          Pedalers Bicycle Tours my website forged with MODX
          vandergraaf-M static website generator for MODX
          • 3749
          • 24,544 Posts
          You can do it with PDO, but it's usually easier just to instantiate MODX and use the code above.

          http://bobsguides.com/blog.html/2013/07/13/using-modx-outside-of-modx/
            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
          • discuss.answer
            • 38593
            • 129 Posts
            Thanks for all the suggestions.

            I ended up going with PDO / PHP totally outside of MODX. Once I figured out the resource IDs and Published status are stored in modx_site_content and the TV values for each resource are stored in modx_site_tmplvar_contentvalues, it was fairly straight forward to construct queries to fetch the data straight from the source.

            This was the final "nice to have" aspect in our quest to turn MODX into a backend static page generator instead of a front active page server. [ed. note: mrcycling last edited this post 11 years ago.]
              Pedalers Bicycle Tours my website forged with MODX
              vandergraaf-M static website generator for MODX
              • 3749
              • 24,544 Posts
              Keep in mind that TVs set to the TV's default value are *not* stored in the contentvalues table. A missing record there means you have to check the TV object's default_text value.

              If no TVs have the default value and none use @ bindings, a lot of complexity goes away and things run much faster (especially if you can use the raw values of the TVs).

              You might also find this helpful: http://bobsguides.com/blog.html/2014/09/29/using-getvalue%28%29-with-tvs/
                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
                • 38593
                • 129 Posts
                @BobRay - Thanks. Fortunately, the TV that I am using has no default or an @ binding, as each one has to be unique for that resource since it will be their url ;-).
                  Pedalers Bicycle Tours my website forged with MODX
                  vandergraaf-M static website generator for MODX