We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34178
    • 212 Posts
    After upgrading revo from ~2.0.0 to 2.1.3-pl it seems like there have been some changes in caching-properties of modx leading to not work anymore our snippet to count page-impressions of our website and save the values to a TV of each resource:

    // get the TV called "counter" of the current document:
    $tvcounter = $modx->getObject('modTemplateVar',array('name'=>'counter'));
    
    // Add 1 and call it newValue:
    $newValue = $modx->resource->getTVValue('counter') + 1;
    
    // Save the TV
    $tvcounter->setValue($modx->resource->get('id'), $newValue);
    $tvzaehler->save();  


    The snippet used to work very well but now it only works once (as long as the resource is still not in the cache (by calling the document for the first time)).

    Does anybody have an idea what we could try to make the snippet work again?

    Letti
      • 3749
      • 24,544 Posts
      Are you calling the snippet uncached?

      [[!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
        • 34178
        • 212 Posts
        Yes, that was my first idea, too. It is called uncached. And to be absolutely sure I start quickemail before and after the the procedure which results in two emails every time the snippet is called but unfortunately without any changing/counting of the TV.

        Is it maybe possible that this is a caching-problem? Maybe that the TV is locked after modified once or the resource is loaded for the first time after clearing the cache?
          • 33976 ☆ A M B ☆
          • 571 Posts
          Hey guys,

          Just a post to let you know there is a setTVValue method since some times now
          see the MODX API
            • 10378
            • 375 Posts
            Hi,

            I'm currently having the same problem! The TV is only written 1 times! I call the snippet unchached.
            Is there a solution in the meantime?

            Greetings,
            Martin
              Freelancer @bitego http://www.bitego.com
              ---
              GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
              More infos here: http://www.bitego.com/extras/goodnews/
              • 3749
              • 24,544 Posts
              You might try:

              $modx->resource->setTVValue('counter', $newValue);


              No need to get or save the TV object.

              [Update] Never mind -- setTVValue() just does exactly what your existing code does.


              ------------------------------------------------------------------------------------------
              PLEASE, PLEASE specify the version of MODX you are using.
              MODX info for everyone: http://bobsguides.com/modx.html [ed. note: BobRay last edited this post 14 years, 4 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
                • 10378
                • 375 Posts
                Hi @lettis,

                could you fix the problem in the meantime?
                I'm still hanging with the fact that the TV is only written once until cache is cleared.

                Greetings,
                Martin
                  Freelancer @bitego http://www.bitego.com
                  ---
                  GoodNews - one of the most advanced and integrated Group Mailer premium add-ons for MODX Revolution!
                  More infos here: http://www.bitego.com/extras/goodnews/
                  • 3749
                  • 24,544 Posts
                  Be sure to make that tag that displays the TV uncached.

                  [[!*tvcounter]]


                  And $tvzaehler in the code above should be $tvcounter.


                  ------------------------------------------------------------------------------------------
                  PLEASE, PLEASE specify the version of MODX you are using.
                  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