1
I’m working with the Zend Framework 2.0 and I noticed that he has a helper for handling error messages, called "flashMessages", which I didn’t understand straight away is whether he captures this by session, or by rendering the view, I’m cracking my head to use this helper, someone can tell me how I could implement this in a form?
Here is my method:
public function userDataAction() {
        $form = $this->getServiceLocator()->get('Admin\Service\FrmUserData');
        $form->setAttribute('action', $this->url()->fromRoute('user-admin', array('action' => 'persist-user')));
        $session = new Container('Admin\Service\FrmSearchUser');
        if (isset($session->data)) {
            $em = $this->getEm();
            $repository = $em->getRepository('Base\Model\Entity\Entities\Document');
            $document = $repository->findOneBy(
                    array(
                        'value' => $session->data['document_cpf'],
                        'type' => 'cpf'
                    )
            );
            if ($document instanceof \Base\Model\Entity\Entities\Document) {
                $user = $repository->searchUserById($document->getUser()->getIdUser());
                $repositoryUser = $this->getEm()->getRepository('Base\Model\Entity\Entities\User');
                $data = $repositoryUser->corrigiCampos($user);
            }
            $form->setData($data);
        }
        if ($this->getRequest()->isPost()) {
            $data = $this->getRequest()->getPost();
            $form->setData($data);
        }
          $messages = null;
        if ($this->flashMessenger()->hasMessages()) {
          /* aqui eu gostaria de setar as mensagens
           de saída como poderia fazer isso? */
           $messages = $this->flashMessenger()->getMessages();
        }
        return new ViewModel(
                array(
                  'form' => $form,
                  'title' => 'Consultar / cadastrar usuário',
                  'subTitle' => 'Preencha os dados abaixo',
                  'messages' => $messages
                )
        );
    }