Jump to content

How to find out if a urlSegment is inside a PageArray

Recommended Posts

i have a event-page with a table.
first column in this table is page-reference-field

how can i find out if a urlSegment matches one of the rows having the same page-reference-field (page-id)?

// all guests
$allguests = new pageArray();
foreach($page->event_guests_table as $event_guests_table_row) {

// echo allguests would output: 1101|1102|1103|…
// domain.tld/event/1101/

// show content if guest is in the table or redirect
if($input->urlSegment1 ~= $allguests ) {
	// show content
else {
	// redirect


which selector operator do i have to use? the one above does not work

Share this post

Link to post
Share on other sites

try has()

$segment = $sanitizer->int($input->urlSegment1);
if($allguests->has($pages->get($segment))) {
    echo "yep";


  • Like 2

Share this post

Link to post
Share on other sites

thx @dragan

this works

if($allguests->has("id=$input->urlSegment1")) {

but i'll do it like you suggested. first sanitizing.

Share this post

Link to post
Share on other sites

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Sanyaissues
      Hi, I have a page with a repeater called teams with two fields: team (a pageReference with a list of teams) and people (a pageReference with a list of people who likes this team).
      I'm trying to populate the people field in the repeater according to the value of the team field in the same repeater. So far. I'm able to get the pageArray that I want to assign to the people field, but i don't know how to "save" the value for each instance of the repeater.
      I hope somebody can give me a light. Thanks in advance.
      $wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) { if($event->object->hasField == 'people') { $repeaterField = $event->arguments('page')->teams; foreach ($repeaterField as $t) { // Is this the way to loop the instances of the repeater? $team = $t->team->id; $t->people = $event->pages->find("template=user, team={$team}"); var_dump($t->people); // This returns the values that i want to assign for each repeate instance $event->return = $t->people; // I hope this assign a custom pageArray for each repeater, but it assigns the same for all the instances of the repeater } } });  
    • By Martin Muzatko
      Hello there!
      I'd love to see more array operation functions such as map/reduce. There are already a few helpful functions there like pop, shift, etc.
      I find myself turning pageArrays into arrays, do array_map or similar and create pageArrays again from that data.
      For Processwire, it would be really helpful to perform forEach operations more comfortably.
      <?php $allTitles = $pages->map(function($page){return $page->title}); // vs traditionally: $allTitles = []; foreach($pages as $page) { array_push($allTitles, $page->title); } $pages->reduce would be really helpful too. This would avoid many in-between variables when calculating sums of fields stored in individual pages.
      Thank you in advance
    • By Davidov
      Good Day!
      I am a beginer of processwire project. Thanks developers for your great work. this CMS is very Good!
      I have a question: how get Pageimage object of PageArray from "Page" (PageArray) field type?
      I have too tamplates: affiliates and their teachers. The template of affiliates have a field "teachers_list" wich is "Page" (PageArray) type.
      When I vaffiliate teachers in a cycle, I can not access the teacher photo object and change its size.   I get an error returning: " Fatal error: Call to a member function maxWidth() on null ". When i trying get URL attribute : $teacherItem->teacher_photo->url, i receive message: " Trying to get property of non-object ".   But this code works: $teacherItem->teacher_photo["url"].   The print_r function outputs the following information: "ProcessWire \ Pageimage Object ([changes] => Array ([0] => formatted) [hooks] => Array ([Pageimage :: pim2Load] => PageImageManipulator02-> getPageImageManipulator02 () in PageImageManipulator02.module ) [Data] => Array ([basename] => p16.jpg [description] => .... - ..... [tags] => [formatted] => 1 [modified] => 1487079115 [created ] => 1487079115))".   my PHP code: foreach ($page->teacher_list as $teacherItem): $out .= " <tr> <td class=\"alignTop\"> /* !!! my truble */ <img src=\"{$teacherItem->teacher_photo->maxWidth(250)->url}\" /> /* !!! my truble */ </td> <td class=\"alignTop\"> <div class=\"teach_style12\"> <strong>$teacherItem->fio</strong><br/> $teacherItem->degree<br/> $teacherItem->headline_detail </div> <div class=\"teach_style9\"> $teacherItem->body </div> </td> </tr>"; endforeach; Please, help me. Where is my error?
    • By Michael Steinmann
      Hello everyone,
      i guess my php knowledge is not good enough to find a solution for the following problem:
      I'm building a website where i have projects. Each project has tags like "webdesign, responsive, cms, print, flyer" etc. At the end of a project i want to recommend other projects, which have similar tags. I want to limit the recommendations to three other projects sorted by the hightest amount of same tags.
      This is how far i got:
      I'm using
      <?php $interessantes = $pages->find("tags=$page->tags, id!=$page->id"); ?> to find other projects with the same tags, excluding the page i'm already on.
      Then i'm using three foreach-functions to go through the projects i found, the tags they have and compare them with the tags of the project i'm looking at. If i have two identical tags, i count up a variable.
      <?php // Projects i have found foreach($interessantes as $interessant): $i = 0; // Tags of the projects i have found foreach($interessant->tags as $tag): // Tags of the project i'm looking at foreach($page->tags as $tagreferenz): if($tag == $tagreferenz): $i++; endif; endforeach; endforeach; endforeach; ?> You can see what it looks like in the screenshot with a bit of HTML. I marked the tags of the current project green and the identical tags of other projects red with the amount of hits below. So in this example i would want to have three projects with three similar tags and get rid of those with only two and one.

      I guess i have to put my pages into an array (with the number of hits?), sort them and echo them with "limit=3"? Unfortunately i have no idea how to do this. You probably have an even better/shorter solution. Links to other topics are welcome to and i'll try to get my head around it.
      If you need further explanation, i'll try my best.
      Best regards
    • By beto
      I can't add a new value to a custom PageArray field  for my user.
      However, when I create a new user, I CAN add the new PageArray value:
      I need help. Thank you very much.
  • Create New...