Hello Processwire community,
I try to build an API which works with PW pages as datastore. A reduced example script looks like this:
<?php
include 'index.php'; // PW bootstrap
$sanitizer = wire('sanitizer');
$id = $sanitizer->selectorValue(wire('input')->get->id);
$page = wire('pages')->get("id=$id");
$lang_code = $sanitizer->selectorValue(wire('input')->get->lang);
$language = wire('languages')->get($lang_code);
$page->of(false);
$output = array(
'content' => $page->content->getLanguageValue($language),
'url' => $page->localUrl($language),
);
header('Content-Type: application/json');
echo json_encode($output);
But this does not work as expected. I get the following error, when I call this script:
Exception: Method Page::localUrl does not exist or is not callable in this context
The "Languages Support - Page Names" module is installed and loaded. I verified this by calling assert(class_exists('LanguageSupportPageNames', false) === true); in the script, which worked.
How can I make this script output the localized URL for a page? I hope you can help me.