We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4195
    • 398 Posts
    I don’t know if it’s really usefull but I needed this functionality for pagination I include in my snippets.
    The function will keep the original url+querystring and keep all values that are not changed intact. This way the link it produces works in every situation.

    For example if your snippet is called together with another snippet that uses some querystring value you can’t possibly now what that value will be unless you preserve the url. When you create a link to a certain ability of your own snippet it will not break the other snippet call.

    you will give either a docid or a docalias of the link and put the extra querystring values in an array.

    function:
    function smartModxUrl($docid, $docalias, $array_values) {
    		global $modx;
    		$array_url = $_GET;
    		$urlstring = array();
    		
    		unset($array_url["id"]);
    		unset($array_url["q"]);
    		
    		$array_url = array_merge($array_url,$array_values);
    
    		foreach ($array_url as $name => $value) {
    			if (!is_null($value)) {
    			  $urlstring[] = $name . '=' . urlencode($value);
    			}
    		}
    		
    		return $modx->makeUrl($docid, $docalias, join('&',$urlstring));
    	}
    


    example usage:
    $link['page'] = 3;
    $link['aname'] = 'avalue';
    $link['another'] = 'one';
    	
    echo smartModxUrl($modx->documentObject["id"],NULL, $link);
    
      Armand Pondman
      MODx Coding Team
      :: Jot :: PHx
      • 7923
      • 4,213 Posts
      Thanks, gonna implement this to the maxigallery pagination too.. don’t know that is it needed in any case, but I can’t think of all ways that the gallery snippet could be used, so I’ll add this just for kicks..

      But I’m a bit worried about this issue with makeUrl api call undecided


        "He can have a lollipop any time he wants to. That's what it means to be a programmer."
        • 4195
        • 398 Posts
        Quote from: doze at Jun 21, 2006, 08:02 AM

        Thanks, gonna implement this to the maxigallery pagination too.. don’t know that is it needed in any case, but I can’t think of all ways that the gallery snippet could be used, so I’ll add this just for kicks..

        But I’m a bit worried about this issue with makeUrl api call undecided

        well to be exact.. the reason i wrote this was because of the maxigallery+replix combination smiley so in reverse if someone adds comments to a gallery.. and you have pagination enabled there will be two pagination abilities (one in maxigallery and one in replix) if you switch to antoher page in the gallery, the comments will switch back to page 1 (that is if you don’t preserve the querystring)
          Armand Pondman
          MODx Coding Team
          :: Jot :: PHx
          • 18397
          • 3,250 Posts
          What is the purpose of this line:

          foreach ($array_values as $name => $value) {
          				$array_url[$name] = $value;
          		}
          
            • 4195
            • 398 Posts
            unnecessary lines of code lol
            can be replaced with

            $array_url = $array_url + $array_values;
            


            the lines fuses the $_GET array and the new values array (thus overwriting any previous value)

            update: changed in original post

            I also want to note that to completely remove a value from teh querystring you have to set it to NULL (not ’’)

            like this: $array[’name’] = NULL;
              Armand Pondman
              MODx Coding Team
              :: Jot :: PHx
              • 4195
              • 398 Posts
              again same line of code replaced with:
              $array_url = array_merge($array_url,$array_values);
              


              because of strange results in some situations.
                Armand Pondman
                MODx Coding Team
                :: Jot :: PHx