Skip to content
This repository has been archived by the owner on Jan 14, 2025. It is now read-only.

Commit

Permalink
Merge pull request #7 from xmon/master
Browse files Browse the repository at this point in the history
Actualización README.md para uso desde Controller
  • Loading branch information
avegao committed May 22, 2016
2 parents da86a76 + 7496815 commit 8da05f8
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public function registerBundles()
```
## Ejemplo de uso

Uso desde la entidad:

```php
<?php

Expand Down Expand Up @@ -132,3 +134,66 @@ class MyEntity {

}
```

Uso desde el controlador:

```php
<?php

namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;

use Xinjia\SpainValidatorBundle\Validator\AllPhone;
use Xinjia\SpainValidatorBundle\Validator\Phone;
use Xinjia\SpainValidatorBundle\Validator\MobilePhone;
use Xinjia\SpainValidatorBundle\Validator\ZipCode;
use Xinjia\SpainValidatorBundle\Validator\DniCif;
use Xinjia\SpainValidatorBundle\Validator\Cif;
use Xinjia\SpainValidatorBundle\Validator\Dni;

class DefaultController extends Controller {

public function indexAction(Request $request) {

$form = $this->createFormBuilder()
->add('telefono', 'text', [
'constraints' => new AllPhone(),
])
->add('telefonoFijo', 'text', [
'constraints' => new Phone(),
])
->add('telefonoMovil', 'text', [
'constraints' => new MobilePhone(),
])
->add('codigoPostal', 'text', [
'constraints' => new ZipCode(),
])
->add('dniCif', 'text', [
'constraints' => new DniCif(),
])
->add('cif', 'text', [
'constraints' => new Cif(),
])
->add('dni', 'text', [
'constraints' => new Dni(),
])
->add('save', 'submit', array('label' => 'Send'))
->getForm();

$form->handleRequest($request);

if ($form->isValid()) {
// ...
}

// replace this example code with whatever you need
return $this->render('AppBundle:Default:index.html.twig', [
'form' => $form->createView(),
]);
}

}

```

0 comments on commit 8da05f8

Please sign in to comment.