3

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)
18

2 Answers 2

2

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 %}
Sign up to request clarification or add additional context in comments.

Comments

-1

@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.

1 Comment

I think that's because when twig try to acces foo.bar it check first whether the property bar is exist with isset($foo->bar) and it fails because there is no such a property and __isset method isn't defined in Doc class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.