$pages->getInfoByPath() method

Get verbose array of info about a given page path

This method accepts a page path (not URL) with optional language segment prefix, additional URL segments and/or pagination number. It translates the given path to information about what page it matches, what type of request it would result in.

If the response property in the return value is 301 or 302, then the redirect property will be populated with a recommend redirect path.

If given a $path argument of /en/foo/bar/page3 on a site that has default language homepage segment of en, a page living at /foo/ that accepts URL segment bar and has pagination enabled, it will return the following:

Example

[
  'request' => '/en/foo/bar/page3',
  'response' => 200, // one of 200, 301, 302, 404, 414
  'type' => 'ok', // response type name
  'errors' => [], // array of error messages indexed by error name
  'redirect' => '/redirect/path/', // suggested path to redirect to or blank
  'page' => [
     'id' => 123, // ID of the page that was found
     'parent_id' => 456,
     'templates_id' => 12,
     'status' => 1,
     'name' => 'foo',
  ],
  'language' => [
     'name' => 'default', // name of language detected
     'segment' => 'en', // segment prefix in path (if any)
     'status' => 1, // language status where 1 is on, 0 is off
   ],
  'parts' => [ // all the parts of the path identified
    [
      'type' => 'language',
      'value' => 'en',
      'language' => 'default'
    ],
    [
      'type' => 'pageName',
      'value' => 'foo',
      'language' => 'default'
    ],
    [
      'type' => 'urlSegment',
      'value' => 'bar',
      'language' => ''
    ],
    [
      'type' => 'pageNum',
      'value' => 'page3',
      'language' => 'default'
    ],
  ],
  'urlSegments' => [ // URL segments identified in order
     'bar',
  ],
  'urlSegmentStr' => 'bar', // URL segment string
  'pageNum' => 3, // requested pagination number
  'pageNumPrefix' => 'page', // prefix used in pagination number
  'scheme' => 'https', // blank if no scheme required, https or http if one of those is required
  'method' => 'pagesRow', // method(s) that were used to find the page
]

Usage

// basic usage
$array = $pages->getInfoByPath(string $path);

// usage with all arguments
$array = $pages->getInfoByPath(string $path, array $options = []);

Arguments

NameType(s)Description
pathstring

Page path optionally including URL segments, language prefix, pagination number

options (optional)array
  • useLanguages (bool): Allow use of multi-language page names? (default=true) Requires LanguageSupportPageNames module installed.
  • useShortcuts (bool): Allow use of shortcut methods for optimization? (default=true) Recommend PagePaths module installed.
  • useHistory (bool): Allow use historical path names? (default=true) Requires PagePathHistory module installed.
  • verbose (bool): Return verbose array of information? (default=true) If false, some optional information will be omitted in return value.

Return value

array


$pages methods and properties

API reference based on ProcessWire core version 3.0.200

Twitter updates

  • Weekly update: Smooth rollout for ProcessWire 3.0.200 main/master, plus getting started on a new WP-to-PW site conversion and why they can be so rewarding— More
    20 May 2022
  • New main/master version of ProcessWire that has more than 220 commits, resolves more than 80 issues, adds numerous new features, performance improvements and optimizations, and consumes HALF the disk space of our previous release— More
    13 May 2022
  • Summary of weekly core updates for 22 April 2022 More
    22 April 2022

Latest news

  • ProcessWire Weekly #419
    In issue 419 of ProcessWire Weekly we'll check out this week's core updates, introduce a brand new recipe of the week, and more. Read on!
    Weekly.pw / 21 May 2022
  • ProcessWire 3.0.200 new master/main version
    This new main/master version has more than 220 commits, resolves more than 80 issues, adds numerous new features, performance improvements and optimizations, and consumes HALF the disk space of our previous release. This post covers all the details.
    Blog / 13 May 2022
  • Subscribe to weekly ProcessWire news

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits