I have this in my Signin controller to listen for a $_POST data:
<?php
use \Phalcon\Tag;
class SigninController extends BaseController {
public function indexAction()
{
Tag::setTitle('Login');
// if submit
if ($_POST) {
$user = Users::findFirst([
"email = :email: AND password = :password:",
"bind" => [
"email" => $this->request->getPost('email'),
"password" => $this->request->getPost('password')
]
]);
if ($user) {
$this->session->set('id', $user->id);
$this->session->set('role', $user->role);
$this->response->redirect("account");
} else {
$this->flash->error('Wrong credentials!');
$this->response->redirect('signin');
}
}
}
}
But the flash message with "Wrong credentials" is not being shown when I submit the form. The page just reloads.
I have this in my base.volt template:
<body>
{{ flash.output() }}
{% block content %}
{% endblock %}
</body>
and it's working for everything except if($_POST) condition.
I have this in my bootstrap file:
$di->set('flash', function() {
$flash = new \Phalcon\Flash\Session([
'error' => 'alert alert-danger',
'success' => 'alert alert-success',
'notice' => 'alert alert-info',
'warning' => 'alert alert-warning',
]);
return $flash;
});
Any idea why the flash messages do not working inside my if($_POST) condition?