Skip to content

Commit

Permalink
Updated README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
Dyer, Andy committed Aug 15, 2018
1 parent 08f241e commit d03ebf1
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ Attach a new instance of `Anddye\Validation\Validator` to your applications cont
it can be accessed anywhere you need.

```php
$app = new \Slim\App;
$app = new \Slim\App();

$container = $app->getContainer();
$container["validator"] = function($container) {
return new Anddye\Validation\Validator;

$container['validator'] = function ($container) {
return new Anddye\Validation\Validator();
};

$app->run();
```

Expand All @@ -44,17 +44,16 @@ where the array key represents the name of the field and the array value represe
the validation rules:

```php
$app->get("/", function (Request $request, Response $response) use($container) {
$validation = $container["validator"]->validate($request, [
"email" => v::email()->length(1, 254)->notEmpty(),
"forename" => v::alpha()->length(1, 100)->notEmpty()->noWhitespace(),
"password" => v::length(8, 100)->notEmpty(),
"surname" => v::alpha()->length(1, 100)->notEmpty()->noWhitespace(),
"username" => v::alnum()->length(1, 32)->notEmpty()->noWhitespace()
$app->get('/', function (Request $request, Response $response) use ($container) {
$validation = $container['validator']->validate($request, [
'email' => v::email()->length(1, 254)->notEmpty(),
'forename' => v::alpha()->length(1, 100)->notEmpty()->noWhitespace(),
'password' => v::length(8, 100)->notEmpty(),
'surname' => v::alpha()->length(1, 100)->notEmpty()->noWhitespace(),
'username' => v::alnum()->length(1, 32)->notEmpty()->noWhitespace(),
]);

// ...

});
```

Expand All @@ -68,7 +67,7 @@ use Respect\Validation\Validator as v;
You can then check if the validation has passed using the `hasPassed()` method:

```php
if(!$validation->hasPassed()) {
if (!$validation->hasPassed()) {
// Validation has not passed
} else {
// Validation has passed
Expand All @@ -79,8 +78,8 @@ If the validation has failed, an array of the validation errors can be accessed
by calling the `getErrors()` method:

```php
foreach($validation->getErrors() as $input => $errors) {
foreach($errors as $error) {
foreach ($validation->getErrors() as $input => $errors) {
foreach ($errors as $error) {
echo $error;
}
}
Expand Down

0 comments on commit d03ebf1

Please sign in to comment.