Skip to content

Instantly share code, notes, and snippets.

@andersonfraga
Last active December 18, 2015 03:09
Show Gist options
  • Save andersonfraga/5716387 to your computer and use it in GitHub Desktop.
Save andersonfraga/5716387 to your computer and use it in GitHub Desktop.
Usando o Respect/Validation para validação.. Tem maneira mais simples de recuperar as falhas na validação?
<?php
namespace Site\Controller;
use Respect\Validation\Validator as v;
class FormController extends BaseController
{
public function faleAction()
{
$postParams = $this->params()->fromPost();
$strNotNull = v::string()->notEmpty();
$errors = array();
if (!$strNotNull->validate($postParams['con-name'])) {
$errors[] = 'o "Nome" não esteja vazio';
}
if (!$strNotNull->email()->validate($postParams['con-mail'])) {
$errors[] = 'o "E-mail" não esteja vazio';
}
if (!$strNotNull->validate($postParams['con-subject'])) {
$errors[] = 'o "Assunto" não esteja vazio';
}
if (!$strNotNull->validate($postParams['con-msg'])) {
$errors[] = 'o "Mensagem" não esteja vazio';
}
// ....
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment