Jump to content

PW Url Shortener


bernhard
 Share

Recommended Posts

Did I already say that I love PW? ?

I had to write an offer today and I wanted to link to a portfolio website that I've built, but the link was too long for the PDF. Then I wanted to use one of the url shortening services, but it felt wrong to put a link like bit.ly/409weifsd on my offer.

I then just enabled UrlSegments on my website's home.php template, added a repeater with fields "title" and "link" and put 5 lines of code to get my very own custom short-links:

$shorturl = $sanitizer->text($input->urlSegment(1));
if($shorturl) {
  $link = @$page->shorturls->findOne("title=$shorturl")->link;
  if(!$link) throw new Wire404Exception();
  $session->redirect($link);
}

Jtk5JRn.png

If you want to try it out: https://www.baumrock.com/pw-demo

 

Any suggestions for improvements are welcome ? 

  • Like 12
Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...