We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 27889
    • 415 Posts
    You can flush the cache:
    function flushcache(){
    global $modx;
       require_once $modx->config['base_path'].'manager/processors/cache_sync.class.processor.php';
       $cache_sync = new synccache;
       $cache_sync->setCachepath($modx->config['base_path'].'assets/cache/');
       $cache_sync->emptyCache();
    }
    
      MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
      MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]
      • 3493
      • 66 Posts
      I wrote this in the beginning of the snippet:
      $pageid = $modx->db->getInsertId(), and then changed the $alias_new to ’doc’.$pageid.’.html’; which returned ’0’...

      Then I placed function flushcache() before $alias_new = ’doc’.$_POST[’id’].’.html’;. That returns nothing at all when using the usual $_POST[’id’] or $modx->db->getInsertId() in $alias_new.

      In other words, I’m still stuck... sad
      Have I done something wrong when I rewrote the snippet, or is it just not possible yet?
        • 27889
        • 415 Posts
        I found a new function which work now (for me smiley ) here it is:
        <?php
        function flush_cache(){
        	global $modx;
        	include_once($modx->config['base_path'] . "manager/processors/cache_sync.class.processor.php");
        	$sync = new synccache();
        	$sync->setCachepath($modx->config['base_path'] . "assets/cache/");
        	$sync->setReport(false);
        	$sync->emptyCache();
        	$modx->clearCache(); // double clear cache
        }
        ?> 
        
          MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
          MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]
          • 29635
          • 361 Posts
          Hmmm... I’m having trouble getting the ID into the alias as well.

          @soda: Could you explain how you’re using that function? I’m not really getting it.

          @doze: That method seems to return ’0’ regardless what I try. I’ve tried using it in conjunction with Soda’s method as well, but I still get a 0.

          I’ve also tried using something like
          "id = {$e->params['id']}"

          but I haven’t had any luck there either.

          The only thing I can get to work is this:
          $id = '.'.$_POST['id'];

          But that only works when editing, not when creating, so it’s kind of useless.
            Need MODx Ecommerce? Try FoxyCart!
            • 27889
            • 415 Posts
            Ooopss I forgot the global $modx, added.

            after my insert query I call the flushcache() function.

            are you sure that [tt]id = {$e->params[’id’]}[/tt] contains your id ?
              MODx Sites & Prestations: http://dp-site.fr [Last MODx Site]
              MODx Repository: [HOME] [MetaTagsExtra] / Current Dev: [xFDM]
              • 29635
              • 361 Posts
              Hi Soda,
              I actually put the global $modx in there when I tried. I’ve tried moving the flush_cache() further down in the code, but the $modx->db->getInsertId(); still returns ’0’...
                  // Update the database
                  $rows_affected = $modx->db->update(
                    $fields, 
                    $table,
                    "id = {$e->params['id']}"
                  );
                  flush_cache();
              

              Do you have this working? If so, could you post the entire plugin as you have it? I have a feeling we’re missing something. Thanks.
                Need MODx Ecommerce? Try FoxyCart!
                • 7923
                • 4,213 Posts
                Sorry, I didn’t look what that getInsertId() actually did, I just remembered that it has been used in some snippets.. but now that I looked, it just returns the id of a previous insert statement. So, if you want the document ID before the document is inserted to the database, that wouldn’t work. You’d have to do a sql what finds out the max id number and ad one to it, but that will only work if no one else gets to create new documents in the meanwhile..


                  "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Quote from: doze at Jan 22, 2007, 03:13 PM

                  Sorry, I didn’t look what that getInsertId() actually did, I just remembered that it has been used in some snippets.. but now that I looked, it just returns the id of a previous insert statement. So, if you want the document ID before the document is inserted to the database, that wouldn’t work. You’d have to do a sql what finds out the max id number and ad one to it, but that will only work if no one else gets to create new documents in the meanwhile..
                  It’s impossible to reliably get a row’s auto-incremented primary key value before it is inserted. You must be able to use getInsertId() after the insert statement takes place to get the id in the same request.
                    • 7923
                    • 4,213 Posts
                    Quote from: OpenGeek at Jan 22, 2007, 03:17 PM

                    Quote from: doze at Jan 22, 2007, 03:13 PM

                    Sorry, I didn’t look what that getInsertId() actually did, I just remembered that it has been used in some snippets.. but now that I looked, it just returns the id of a previous insert statement. So, if you want the document ID before the document is inserted to the database, that wouldn’t work. You’d have to do a sql what finds out the max id number and ad one to it, but that will only work if no one else gets to create new documents in the meanwhile..
                    It’s impossible to reliably get a row’s auto-incremented primary key value before it is inserted. You must be able to use getInsertId() after the insert statement takes place to get the id in the same request.
                    But could even the getInsertId() in theory return the wrong value if multiple documents were inserted at the same time by different requests..?

                    Anyways, I don’t know why getInsertId() does return 0, because I checked and the insert statement is run before the event is being invoked..

                    But here’s how you can get the id of the newly created document: $modx->event->params[’id’]


                      "He can have a lollipop any time he wants to. That's what it means to be a programmer."
                      • 29635
                      • 361 Posts
                      Quote from: doze at Jan 22, 2007, 04:03 PM

                      But here’s how you can get the id of the newly created document: $modx->event->params[’id’]

                      That’s working perfectly for me. Thanks.
                        Need MODx Ecommerce? Try FoxyCart!