Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2-Twig- Accessing stdclass object array

Tags:

twig

symfony

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)
like image 310
behrus Avatar asked Mar 08 '26 00:03

behrus


1 Answers

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 %}
like image 61
Matteo Avatar answered Mar 10 '26 15:03

Matteo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!