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

Volt: Cannot pass variable from Controller to View

I went through documentation on Volt and did not see the example with setVar function.

So this is my code in Controller:

if(!$valid) {

            $this->view->setVar("No Email", $error);
        }

the code in my volt file:

<input type="text" name="email" placeholder="Employee email" />{{ error }}

I am getting "Undefined variable: error"

What i am doing wrong?



8.1k


14.9k

alright, i changed it to No_Email, but it did not help, result is the same.



6.9k
Accepted
answer
edited Apr '15

Check out the API Docs for the view class. Class Phalcon\Mvc\View

I linked to Google because there appears to be a bug with the forum when the link contains wrapping underscores

public Phalcon\Mvc\View setVar (string $key, mixed $value)

You have your argument placements mixed around, 1st argument is key, so you should be referencing that within your view and not the value.

//ie.
if(!$valid) {
    $this->view->setVar('error', 'No email');
}