We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Volt's compatibility with MongoDB

Hello folks,

i'm using PhalconPHP with MongoDB and find some kind of issue, i think.

I have a collection like this:

someKey: {
    anotherKey:"Hello"
},
normalKey:"World!"

When i try to access the "anotherKey" with Volt, it just don't works...:

<h1>
{{myControllerVar.someKey.anotherKey}}, {{myControllerVar.normalKey}}
</h1>

The "normalKey" appears normally but "anotherKey" don't. Is it a bug? Or there is another way to access subkeys in Volt's engine?

Found another quirk...

When i try to print the "_id" value in Volt's view, if i use: json {{ product._id }} it throws me this error (obviously the cause is the underline bad interpretation):

PhalconException: Parsing error before 'id }}'

and even if i use the braces type json {{ product['_id'] }} it don't throws any error, but don't print any rows bellow the first one.

Any ideas?



98.9k
Accepted
answer

It seems you're running an old version, check this gist out https://gist.github.com/phalcon/5385169

It's compiling without problem: http://test.phalcon.io/volt.php

Regarding the collection, if you're accessing an object, you must use . (dot) and if you're accessing arrays you must use square brackets [ ]

The problem was the version, i was using Phalcon version 0.9.1.

I've updated to 1.0.1 and now its working without problems... thanks!