We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 29860
    • 59 Posts
    Hi
    I am using 2.0.7
    Can someone tell me how the to get a specific tv from a specific resource?

    I have the following code :
      
      //we are being called from the doc id 12
      $modx->getObject('modResource', 8); //set the new respurce id of 8
      echo $modx->resource->get('id').'<br>'; //returns 12, the original resource id, shouldnt this be 8 now?
      $val = $modx->resource->getTVValue('afflink');
    


    I also tried :
      
      $doc = $modx->getObject('modResource', 8); //set the new respurce id of 8
      echo $doc->resource->get('id').'<br>'; //returns 12, the original resource id, shouldnt this be 8 now?
      $val = $doc->resource->getTVValue('afflink');
    



      • 18373 ☆ A M B ☆
      • 3,141 Posts
      You should be doing this:


      $res = $modx->getObject('modResource',8); // Now $res is an object which represents resource 8
      $tvvalue = $res->getTVValue('afflink'); // The value of the TV called "afflink" will now be in the $tvvalue var


      $modx->resource always returns the current resource object, so you will want to set the value of $modx->getObject to a different variable..
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 29860
        • 59 Posts
        thanks!