3
votes

may be someone can explain me what i am goting wrong.

I get response from riak bucket, which i prepare in action controller and render the response in twig. But i can not iterate over the response with loop in twig.

When i do that in twig:

{%% for callback in callbacks %}
 {{ dump(callback) }}
 {% endfor %}

I get this:

Doc {#410 ▼   
  #data: {#422 ▼
    +"psStatus_i": 0
    +"psUrl_s": ""
    +"clickId_s": "1_3_4_f1a9bcf2faaa2ef67a39916ba06cbbb0"
    +"id_s": "565f04da60030fa3048b4572"   
  }   
#_yz_id:1*CallBackDataIn_all*all*1_3_4_f1a9bcf2faaa2ef67a39916ba06cbbb0*24"   
}

but when i want to get explicit one field like:

{{ callback.id_s }}

i get then:

Method "id_s" for object "Basho\Riak\Search\Doc" does not exist

I try to cast to array bvt then i get array to string exception.

Any idea, what i am doing wrong.

EDIT: This is output with var_dump() in php:

object(Basho\Riak\Search\Doc)[410]   protected 'data' => 
    object(stdClass)[422]
      public 'psStatus_i' => int 0
      public 'psUrl_s' => string '' (length=0)
      public 'clickId_s' => string '1_3_4_f1a9bcf2faaa2ef67a39916ba06cbbb0' (length=38)
      public 'id_s' => string '565f04da60030fa3048b4572' (length=24)   
protected '_yz_id' => string                 '1*CallBackDataIn_all*all*1_3_4_f1a9bcf2faaa2ef67a39916ba06cbbb0*25' (length=66)   
protected '_yz_rk' => string '1_3_4_f1a9bcf2faaa2ef67a39916ba06cbbb0' (length=38)
2
try {{ callback.data.id_s }}Matteo
use {{ callback['id_s'] }}, the dot notation is assuming the use of getter functions on the objectRooneyl
@Matteo: tried already before posting....but the same exception: Method "id_s" for object "Basho\Riak\Search\Doc" does not existbehrus
May be attribute(callback, 'id_s') will do the trick?Vasily
try {{ callback.__get('id_s') }Matteo

2 Answers

2
votes

In accordion with the source code of the class, you can access yo the value as follow:

{%% for callback in callbacks %}
    {{ callback.__get('id_s') }
{% endfor %}
-1
votes

@Matteo Once again thx. But i am little bit confused because i ask myself why it works in php with $callBack->id_s without magic __get() and not in twig?

Another question, do you recommend remialvado? Basho is the official php_client for Riak.