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: 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?



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

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.

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