Jump to content

Recommended Posts

Posted

Hey.

I've got a template with a statistics repeater field

the repeater field contains 4 fields

-statistics

--stat_type

--data_version

--value

--future_data

In the same template there's also a field called game_id. 

When I use the following selector I get a page back but I can't access the value:

$pages->get("statistics.stat_type=ITEM1, game_id=877760255");

I've used the Selector module and it returned 2 pages, but thats because it uses find.

How can i access the value field?

Posted

I think theres possibly some inconsistent behavior with get and find when using more sophisticated selectors. Just use a find with a limit =1 and a first () chained.

Posted

When I use the following selector I get a page back but I can't access the value:

Which value?

Posted

So you tried something like this:

$p = $pages->get("statistics.stat_type=ITEM1, game_id=877760255");
// First value
$value = $p->statistics->first()->value;

Can you post your code?

If you have the page, then statistics still contains all the pages with different ITEMs I guess.

Posted

Error: Exception: Method Page::first does not exist or is not callable in this context (in C:\wamp\www\social\wire\core\Wire.php line 232)

Thats the result Wanze.

Thats what I expected since var_dump returns NULL... So theres no array or object returned...

This is how I make the repeater values:

foreach($match->statistics->array as $statistic){
   $s = $p->statistics->getNew();
   $s->stat_type = $statistic->statType;
   $s->data_version = $statistic->dataVersion;
   $s->value = $statistic->value;
   $s->future_data = $statistic->futureData;
   $s->save();
}

And this is how i try to get the items:

for($i=1;$i<7;$i++){
   $item = $this->pages->find("statistics.stat_type=ITEM" . $i . ", game_id=$match->game_id, limit=1");
   if($item->id){
      $item1 = $item->first();
      $this->html .= $item1->value;
   }
}

Also tried:

for($i=1;$i<7;$i++){
   $item = $this->pages->get("statistics.stat_type=ITEM" . $i . ", game_id=$match->game_id, limit=1");
   if($item->id){
      $item1 = $item->first();
      $this->html .= $item1->value;
   }
} 

Or:

for($i=1;$i<7;$i++){
   $item = $this->pages->find("statistics.stat_type=ITEM" . $i . ", game_id=$match->game_id, limit=1");
   if($item->id){
      $val= $item->first()->value;
      $this->html .= $val;
   }
} 
Posted
$item = $this->pages->get("statistics.stat_type=ITEM" . $i . ", game_id=$match->game_id, limit=1");
   if($item->id){
      $item1 = $item->first();
      $this->html .= $item1->value;
   }

$item is the page containing the repeater, not the repeater itself.

Your value field is in the pages inside the repeater:

$statistics = $item->statistics;
foreach ($statistics as $stat) {
  // Value is a field in the repeater
  echo $stat->value;
}
  • Like 1

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.
×
×
  • Create New...