We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4172
    • 5,888 Posts
    how did you call that snippet?
      -------------------------------

      you can buy me a beer, if you like MIGX

      http://webcmsolutions.de/migx.html

      Thanks!
      • 51020
      • 670 Posts
      Quote from: Bruno17 at Nov 20, 2017, 09:49 AM
      how did you call that snippet?

      I added it to the content of a resource with no template, and then viewed the resource.
      
      [[!snippetName]]
      
      


      Is that wrong?
      Thanks again
      Andy
        • 4172
        • 5,888 Posts
        thats looking good, but try this snippet, it gives maybe a bit more information, what happens:

        <?php
        $removeresources = '111,112,999999,9998888';
        
        $removeresources = explode(',',$removeresources);
        
        foreach ($removeresources as $id) {
            if ($doc = $modx->getObject('modResource',$id)){
                if ($doc->remove()){
                    echo 'removed ' . $id . '<br>';
                } else {
                    echo 'could not remove ' . $id . '<br>';
                }        
            } else {
                echo 'could not find ' . $id . '<br>';    
            }
        }
        
        
          -------------------------------

          you can buy me a beer, if you like MIGX

          http://webcmsolutions.de/migx.html

          Thanks!
          • 51020
          • 670 Posts
          Quote from: Bruno17 at Nov 20, 2017, 11:58 AM
          thats looking good, but try this snippet, it gives maybe a bit more information, what happens:

          <!--?php
          $removeresources = '111,112,999999,9998888';
          
          $removeresources = explode(',',$removeresources);
          
          foreach ($removeresources as $id) {
              if ($doc = $modx--->getObject('modResource',$id)){
                  if ($doc->remove()){
                      echo 'removed ' . $id . '
          ';
                  } else {
                      echo 'could not remove ' . $id . '
          ';
                  }        
              } else {
                  echo 'could not find ' . $id . '
          ';    
              }
          }
          
          

          Thanks!
          So this is the output on the page:

          could not find 23
          could not find 24
          could not find 25
          could not find 35
          could not find 54
          could not find 55
          could not find 56
          could not find 57
          could not find 58
          could not find 59
          could not find 60
          could not find 61
          could not find 62
          could not find 63
          could not find 64
          could not find 65
          could not find 66
          could not find 67
          could not find 68
          could not find 69
          could not find 70
          could not find 79
          could not find 80
          could not find 81
          could not find 82
          could not find 89
          could not find 90

          I keep checking the database to make sure I'm not imagining it - but they are there (I promise!)

            • 4172
            • 5,888 Posts
            are you logged into the manager and you are sure, you have permissions to load that resources?
            maybe you should check, to be sudo-user
            check also the MODX - errorlog
              -------------------------------

              you can buy me a beer, if you like MIGX

              http://webcmsolutions.de/migx.html

              Thanks!
              • 51020
              • 670 Posts
              Quote from: Bruno17 at Nov 20, 2017, 03:28 PM
              are you logged into the manager and you are sure, you have permissions to load that resources?
              maybe you should check, to be sudo-user

              Yes this is one thing I did check - because I had run out of things to check - but I'm the only user in the list, and I am sudo.

              if I try and view resource ID23, I get this error:
              Resource with ID 23 not found

              The only place I can see the resource is in the db directly.

              Thanks for the suggestion though.
                • 3749
                • 24,544 Posts
                I suspect that it's because the snippet is running in the front end. When you view the front end from the Manager, you're the anonymous user. You need to explicitly log in to the front end as the admin using the Login snippet.
                  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
                  • 51020
                  • 670 Posts
                  Quote from: BobRay at Nov 20, 2017, 11:14 PM
                  I suspect that it's because the snippet is running in the front end. When you view the front end from the Manager, you're the anonymous user. You need to explicitly log in to the front end as the admin using the Login snippet.

                  Hmm OK - I will give that a go too.
                    • 51020
                    • 670 Posts
                    Quote from: BobRay at Nov 20, 2017, 11:14 PM
                    I suspect that it's because the snippet is running in the front end. When you view the front end from the Manager, you're the anonymous user. You need to explicitly log in to the front end as the admin using the Login snippet.

                    OK so I have added a login page on the front end - which directs me to the fix articles resources.
                    I have added this to the top of the page, to verify I am logged in:
                    [[!Profile]]
                    <p>Username: [[+username]]<br /> Email: [[+email]]<br /> State: [[+state]]</p>
                    


                    But it still says:

                    could not find 23
                    could not find 24
                    could not find 25
                    could not find 35
                    could not find 54
                    could not find 55
                    could not find 56
                    could not find 57
                    could not find 58
                    could not find 59
                    etc...
                    
                      • 3749
                      • 24,544 Posts
                      Try changing the getObject() line to this:

                      if ($doc = $modx->getObject('modResource',(int) $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