We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36926
    • 701 Posts
    Hi i'm trying to run a small snippet to set the isfolder and not having a lot of luck. I have the following

    <?php
    $resource = $modx->getObject('modResource', 22);
    
    $resource->set('isfolder', 1);
    $resource->save();
    
    return '<p>The resource is now a folder</p>';
    
    


    What am i missing?
      • 22303 MODX Staff
      • 10,725 Posts
      What is not working? Is the database not changing? Or are you not seeing the change after clearing the cache?
        • 36926
        • 701 Posts
        I'm not getting anything, I don't even get the return. Just a blank page. Checked DB and this doesn't change

        I'm using revo 2.1.5
          • 3749
          • 24,544 Posts
          Try this:

          <?php
          $resource = $modx->getObject('modResource', 22);
           
          if (! $resource) {
             return '<p>Could not find resource 22</p>';
          }
          $resource->set('isfolder', 1);
          $resource->save();
           
          return '<p>The resource is now a folder</p>';



          ---------------------------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
          MODX info for everyone: http://bobsguides.com/modx.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
            • 36926
            • 701 Posts
            Thanks Bob, thats done the trick. Any idea wasn't the other way working, i'd actually tried my first way on another 2.1.5 fresh instal on same local server and it worked fine.

            Thanks again
              • 36926
              • 701 Posts
              I'm trying to fix my issue mentioned in this post. I'm wondering if i could loop for all resources and set the isfolder to it's current value to force a URI regeneration.

              Should the following work?
              $resources = $modx->getCollection('modResource');
              
              foreach ($resources as $resource) {
               $value = $resource->get('isfolder');
               $resource->set('isfolder', $value);
               $resource->save();
              }
              
              return '<p>Resources Set</p>';
              
              
                • 36926
                • 701 Posts
                Ok ran the above and seems to of worked fine.