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
)
);
}