We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    This is driving me nuts.

    I have a plugin connected to OnWebPagePrerender that acts on the basis of certain TV values of the current resource. Since some actions are one-time-only, I reset the TV values in the plugin and save them. This worked fine until 2.2.

    Unfortunately, the old values of the TVs now persist unless the user reloads the Manager page.

    It appears that the TV values are in memory in the $modx->resource object and that's where the value comes from with either $tv->getValue() or $resource->getTVValue(). The TV values don't change even with a page reload in the front end and refreshing the cache.

    Is there any way to alter the TV values stored in $modx->resource or to retrieve the actual TV for a resource from the DB, or any other method that will get me the fresh TV value?
      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
      • 3749
      • 24,544 Posts
      Ok, I found a way around it -- setting the TV fields of the $resource object:

      $fields = array (
          'SendTestEmail',
          'No',
          'default',
          '',
          'option',
      );
      $modx->resource->set('SendTestEmail', $fields);



      Let me know if there's a better way.
        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
        • 28042 ☆ A M B ☆
        • 24,524 Posts
        How are you saving the tv value? Wouldn't you use the resource->set, then resource->save? Not that I have the slightest idea what I'm talking about when it comes to Revo.
          Studying MODX in the desert - http://sottwell.com
          Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
          Join the Slack Community - http://modx.org
          • 3749
          • 24,544 Posts
          The typical way of setting TV values when you have the resource is $resource->setTVValue(). That saves the new version of the TV to the DB.

          I'm doing that, but it doesn't 'take' because $resource->getTVValue() gets the value from the $resource object in memory, which isn't modified by setTVValue() (though I think it probably should be), so I need the extra code above in addition to setTVValue().

          I should mention that I'm guessing about how this all works. My solution is based on a theory and seems to work, but I could be wrong about what's happening under the hood.

          ---------------------------------------------------------------------------------------------------------------
          PLEASE, PLEASE specify the version of MODX you are using . . . PLEASE!
          MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 14 years, 6 months ago.]
            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