Use stdClass in Templates

majafy

Member
Hi,

I have a stdClass variable which created in PHP, I use $template->create to pass it to my template.

this is my template code :
PHP:
<xen:foreach loop="$data" value="$i">
    {$i.name}<br>
</xen:foreach>

But because $i is an object I get this error:
Fatal error: Cannot use object of type stdClass as array in ...


How Can I use stdClass in my templates?


Regards
 
You can't unless it has array like behaviours such as implementing ArrayAccess or similar.

Is this related to your JSON data from the other thread? If so, json_decode supports outputting an associative array rather than an object:

PHP:
$array = json_decode($json, true);
 
You can't unless it has array like behaviours such as implementing ArrayAccess or similar.

Is this related to your JSON data from the other thread? If so, json_decode supports outputting an associative array rather than an object:

PHP:
$array = json_decode($json, true);
Thanks again Chris ;)

Yes, This problem related to JSON question,
I found this solution earlier, but I think there is a way to use object.
anyway thank you for your help.
 
Back
Top Bottom