Quantcast
Channel:
Viewing all articles
Browse latest Browse all 4235

Re: Redirect to current URL (with URL params)

$
0
0

Thanks guys. I was really checking to see if Silverstipe had a built in method of simply obtaining the pages current URL including the Query String. It looks like it doesn't.

Your examples will work, as long as "saved" or "success" are passed in the url. But in this case, the query string could be a number of things. Or not there at all for some pages. All I was looking for is get whatever is in the query string without resorting to plain PHP to keep things neat. I would have thought this would be common enough for it to warrant an existing helper.

I have solved this by making a method that simply returns the current URL in it's entirety. Placed this in my central Applicatoin file, and can now get any current URL in full by calling Application::curPageURL();

/**
    * Just get the current URL
    * @return string
    */
   static function curPageURL() {
      $pageURL = 'http';
      if (Director::protocol() == 'https') {$pageURL .= "s";}
      $pageURL .= "://";
      if ($_SERVER["SERVER_PORT"] != "80") {
         $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
      } else {
         $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
      }
      return $pageURL;
   }


Posted to: Redirect to current URL (with URL params) | Show Thread | Post Reply


Viewing all articles
Browse latest Browse all 4235

Trending Articles