Good Day.
First of all, I want to thank the Phalcon team for this amazing framework.
I am uncountering a weird error in passing variables to Volt. Whenever I try supplying finders with conditions, it always return as expected, but when I pass it to the view, it displays, but there is always either following error message in PHP error logs:
"[Mon Dec 05 15:16:04.014342 2016] [:error] [pid 9440] [client 127.0.0.1:58694] PHP Notice: Undefined variable: user in /var/www/html/cache/_var_www_html_app_views_index_index.volt.php on line 11, referer: https://localhost/charles"
OR
"[Mon Dec 05 15:16:04.014356 2016] [:error] [pid 9440] [client 127.0.0.1:58694] PHP Notice: Trying to get property of non-object in /var/www/html/cache/_var_www_html_app_views_index_index.volt.php on line 11, referer: https://localhost/charles"
// Controller //
public function indexController($username = null) {
$user = User::findFirst(
[
"conditions" => "username = :username:",
"bind" =>
[
"username" => $username
],
"columns" =>
[
"id", "username"
]
]
);
$this->view->user = $user;
// even if I use $this->view->setVar("user", $user);
}
// Volt //
{{ user.username }}
or
{{ user["username"] }}
However, when I try to use finders with only the ID used, there is no error.
public function indexController($username = null) {
$user = User::findFirst(1);
$this->view->user = $user;
// even if I use $this->view->setVar("user", $user);
}
// Volt //
{{ user.username }}
or
{{ user["username"] }}
Any help would be appreciated. I know the code still works, either way. However, I will loose my PHP error logs if these errors persists.
*Note: I have also made changes to the router for the index controller to accept parameters without needing to add the additional "index" in the URL.
$di->set("router", function() { $router = new Router(); // Router changes
$router->add("/{username}", [
"controller" => "index",
"action" => "index",
]);
$router->add("/{username}/page", [
"controller" => "index",
"action" => "index",
]);
$router->add("/{username}/page/{page:\d+}", [
"controller" => "index",
"action" => "index",
$router->removeExtraSlashes(true);
return $router;
}, true);