I want to populate a select field with a filtered set of pages from the site so they can be picked from the select, using autoid field as the value. I don’t know how to get it into the right format expected by the Select field.
Heres what I’ve got. How do i tweak it so the I get a nice title in the select filed, and i can use that to get the selected pages URL? This is to populate a link url on the front end.
I am usng a route to do it and heres what I have:
// Page Links
array(
'pattern' => 'pagelist.json',
'action' => function() {
header('Content-type: application/json; charset=utf-8');
$pages = site()->index()->visible()->filterBy('template', 'not in', ['error', 'blogarticle']);
$json = array();
foreach ($pages as $page) {
$json[] = (string)$page->url();
}
echo json_encode($json);
}
),
What do you want with the URL? Didn’t you say you want to store the autoid as the value and the Title as what is shown to the user?
Then the autoid should be the key in your generated json and the title the value. The way you are generating your array, you only get a number as key.
foreach ($pages as $page) {
$json[$page->autoid()] = $page->title()->value();
}
Basically i want to be able to pick any page from the select and be able to get that pages URL somehow, so i can populate a link on the front end.
I just picked on AutoID becuase it’s set in stone. If use AutoID as the value, I will have a bunch of numbers in the select feild.
Maybe theres another way… 
I you use the code I posted above, the autoid will be the value that is saved in your file, while the title is what is shown as the select option-
I tried but i get a whoops: Illegal off set type…
// Page Links
array(
'pattern' => 'pagelist.json',
'action' => function() {
header('Content-type: application/json; charset=utf-8');
$pages = site()->index()->visible()->filterBy('template', 'not in', ['error', 'blogarticle']);
$json = array();
foreach ($pages as $page) {
$json[$page->autoid()] = $page->title()->value();
}
echo json_encode($json);
}
),
Maybe you have to use ->value() as well for the autoid…
Bingo! That did it. Thank you. 