We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36711
    • 68 Posts
    I have a snippet which goes through some IDs and displays a list of related products (resources). Meanwhile deleted resources cause error in this snippet. $modx->getObject cause error on not exists resorce IDs. Would it be possible to check a resource presence by ID?

    here is a part of the snippet:
    for ($i= 0; $i < count($arr); $i++) {
        $document = $modx->getObject('modResource',$arr[$i]);
    }


    I use MODX Rev 2.1.3-pl (advanced)

    thanx in advance
      sherlockseo
      • 4172
      • 5,888 Posts
      you can do

      if ($document = $modx->getObject('modResource',$arr[$i])){
          //do somthing with the document
      }


      I think its better to get them with getCollection or getIterator in one go.

      if ($collection = $modx->getCollection('modResource',array('id:IN' => $arr))){
          foreach ($collection as $document){
              //do something with the document
          }
      }


        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 36711
        • 68 Posts
        hi Bruno

        sorry, we had a short vacation over here
        today we managed to solve this issue thanx to your support

        many thanks!!!
          sherlockseo