I've just had a look: {{ form.messages("name") }}
is pulling from $form = new SignUpForm();
looking at the link. If you take a look at the volt layout's controller >> https://github.com/phalcon/vokuro/blob/master/app/controllers/SessionController.php << You will see that the signupAction()
creates a $form
variable and inserts a new SignUpForm()
object in to it.
<?php
/**
* Allow a user to signup to the system
*/
public function signupAction()
{
$form = new SignUpForm();
if ($this->request->isPost()) {
if ($form->isValid($this->request->getPost()) != false) {
$user = new Users();
$user->assign(array(
'name' => $this->request->getPost('name', 'striptags'),
'email' => $this->request->getPost('email'),
'password' => $this->security->hash($this->request->getPost('password')),
'profilesId' => 2
));
if ($user->save()) {
return $this->dispatcher->forward(array(
'controller' => 'index',
'action' => 'index'
));
}
$this->flash->error($user->getMessages());
}
}
$this->view->form = $form;
}
The form object is then being passed to the volt view via $this->view->form = $form
which is why volt can access them via {{ form.messages(THE_FIELD_NAME) }}
so I can only imagine that because SignUpForm extends Form
that the messages are being created within /Phalcon/Form via . I think, I don't know, I think these messages are being created what $this->getMessagesFor($name)
is being called.
See getMessages in https://docs.phalcon.io/en/latest/api/Phalcon_Forms_Form.html
You could check by placing print_r($form); exit;
before $this->view->form = $form
and use your browser find for 'messages' or even print_r($form->messages); exit;
as an experiment.
My guess would be that:
<?php
public function messages($name)
{
if ($this->hasMessagesFor($name) && $this->request->isPost()) {
foreach ($this->getMessagesFor($name) as $message) {
$this->flash->error($message);
}
}
}
...would be fine to use. If I'm right that is.