We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 43419
    • 8 Posts
    Hello guys,
    I would like to refresh the resource page when I save it. Is this possible ? Thanks for you answer !
      • 3749
      • 24,544 Posts
      I'm not sure what you mean by 'refresh the resource page.'

      What version of MODX?
        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
        • 43419
        • 8 Posts
        Thanks for your answer !
        I'm using the Modx Evolution 1.0.7.
        Actually, I developped a plugin to fill automatically some input field in the resource page when you save for the first time. This is work fine, I change the value in my database but in my resource input I have to reload the page to see the change and if I don't, I 'll save the last value. So I'm looking a way to automate the reload of the page when I save (like if I pressed F5 ).
        Thanks
          • 3749
          • 24,544 Posts
          I know how to do that in Revolution, but I'm afraid I don't remember the method in Evolution.

          You might poke around in the old NewsPublisher snippet. I'm pretty sure it clears the cache after saving a resource.

          Search for the word "cache".
            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
            • 43419
            • 8 Posts
            Thanks you very much I find an alternative, I just creat a new table in my database so I don't have a cache problem.
            But thanks !
              • 21508
              • 46 Posts
              Quote from: BobRay at May 29, 2013, 11:38 PM
              I know how to do that in Revolution
              Hi Bob, can you explain me how to make in Revolution,
              I try
              $modx->cacheManager->refresh();

              but did not help.
              Modx revo 2.2.9
                It’s Nice to Be Important, But It’s More Important to Be Nice
                • 3749
                • 24,544 Posts
                See if this works:

                $cm = $modx-getCacheManager();
                $cm->refresh();
                  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
                  • 39437
                  • 13 Posts
                  I tried with:
                  $cm = $modx->getCacheManager();
                  $cm->refresh();

                  But no success.
                    MODX Rocks I am so glad that I have found it.
                    • 3749
                    • 24,544 Posts
                    If it's a new resource, you also have to add this:

                    $modx->reloadContext('web'); /* or whatever context the resource is in */
                      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
                    • I have been trying to get this reload to work in Revo 2.3.3 in a plugin that fires on OnDocFormSave, but it just doesn't reload the resource.

                      I am creating a value for a TV on save (getting Lat Long coords based on a provided address) and would like to have the field filled in after the doc is saved.

                      plugin code below
                       $eventName = $modx->event->name;
                          switch($eventName) {
                              case "OnDocFormPrerender":
                                  //add custom CSS for the TV elements in the settings panel
                                  $modx->regClientCSS(MODX_ASSETS_URL.'customizations/property.css');
                                  break;
                              case "OnDocFormSave":
                                  //make the GeoCode call and save result to the tv latlng
                                 
                                  $addr = $resource->get('description');
                                  if(!empty($addr)){
                                      $url = 'http://maps.google.com/maps/api/geocode/json?sensor=false&address='.str_replace (" ", "+", urlencode($addr));
                                      $ch = curl_init();
                                         curl_setopt($ch, CURLOPT_URL, $url);
                                         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
                                         $response = json_decode(curl_exec($ch), true);
                                         if ($response['status'] != 'OK') {
                                             return 'geocode failed';
                                             
                                         }
                                          $geometry = $response['results'][0]['geometry'];
                                          $lat = $geometry['location']['lat'];
                                          $long = $geometry['location']['lng'];
                                          $resource->setTVValue('latlng', $lat.', '.$long);
                                         }
                                         $cm = $modx->getCacheManager();
                                        $cm->refresh();
                                      
                                  break;
                              default:
                                  break;
                          }
                      return;


                      The TV is saving as expected, it just would be a better user experience to have the page refresh with the values in place without a manual refresh.