ProcessWire - URL Segments

Aus Wikizone
Wechseln zu: Navigation, Suche

URL Segemente kann man in PW ähnlich auswerten wie GET Parameter

https://processwire.com/docs/front-end/how-to-use-url-segments/#best-practices

Beispiel

// we are only using 1 URL segment, so send a 404 if there's more than 1
if(strlen($input->urlSegment2)) throw new Wire404Exception();

switch($input->urlSegment1) {
  case '':
    // Segment 1 is empty so display main content
    break;

  case 'photos':
    // Display photo gallery
    break;

  case 'map':
    // Display map
    break;

  default:
    // Anything else? Throw a 404
    throw new Wire404Exception();
}

== Sanitzier für URL-Segmente? ==
Eventuell dieser:
 $sanitizer->pageName($input->urlSegment1, true); // URL segments are already sanitized as page names but not to lowercase