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

Controller variables usable in volt view

Hi there,

I found out recently, that php variables defined in the controller are usable volt templates.

Why is that even a thing ? What is the purpose of using setVar/setVars ?

Is there any option to disable this behaviour ?

Greetings

Which version of Phalcon are you using?

I've just checked it with 2.0.13 and local controller variables are not visible from the view, only if you expose them explicitly with the view service.

I think MollocH means the controller's properties ($this->property), not the variables in a controller's function. I assume it was done for convenience.

Same applies for 2.0.x, setting a property on the controller will not show up in the view context...

I'm guessing it's something new in the v3 branch.

In php 7 it's pretty much a bug that you can use variables from current scope in view, in php 5 it work fine. But i think it is fixed already on latest phalcon.



43.9k

Hi,

What is the purpose of using setVar/setVars ?

to pass variables from controller's action to the corresponding view

But I'm not sure that I've really understood MollocH's question