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

Accessing an entire object in volt

I've got an object injected into the DI:

$di->setShared('myobject', function(){
    return new \NS\Object('whatever');
});

Now I can access object methods/variables in volt no problem:

{{ myobject.doSomething('somevar') }}

// results in php code: 
$this->myobject->doSomething('somevar');

However, if I want to pass that entire object to another function using volt, it doesn't work:

{{ anotherobject.doSomethingWithObject(myobject) }}

// results in php code -- note lack of $this
$this->anotherobject->doSomethingWithObject($myobject);

Is there another volt function I need to use to ensure the DI injected object is used? And not just a local $object instead?

Thanks.



34.6k
Accepted
answer

Try:

{{ anotherobject.doSomethingWithObject(this.myobject) }}

Also, this should work:

{{ this.myobject.doSomething('somevar') }}


14.9k

That works -- thanks!