We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Accesing model data in array

I'm trying to use {{ modelData()["user"].name() }} to acces a User instance's name, but Volt gets an unexpected -> in the template. The compiled template shows me that the result is (POST::getModelData()["user"])->name(), so... is there a way to avoid the parenthesis?



33.8k

Try `{{ modelData()["user"].name() }}

Ups, edited the code. That was what I have, not ->.



33.8k

Ok ok, I did a work around setting a var with the array's data:

{% set aux = modelData()["user"] %}

This way I can avoid the parenthesis, because aux is just a single object (thing, said in some form), but modelData()["user"] has to be englobed, because I'm trying to access something (name() method) in a subobject (modelData()["user"]).