10000 confirmation · jzawadzki/symfony-standard@ec00a7b · GitHub
[go: up one dir, main page]

Skip to content

Commit ec00a7b

Browse files
committed
confirmation
1 parent 98f42c7 commit ec00a7b

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

src/AppBundle/Controller/DefaultController.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace AppBundle\Controller;
44

5+
use AppBundle\Entity\Test;
6+
use AppBundle\Form\TestType;
57
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
68
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
79
use Symfony\Component\HttpFoundation\Request;
@@ -13,9 +15,17 @@ class DefaultController extends Controller
1315
*/
1416
public function indexAction(Request $request)
1517
{
18+
$test = new Test();
19+
$form = $this->createForm(TestType::class, $test,['csrf_protection'=>false]);
20+
$form->submit(['url'=>'http://symfony.com']);
21+
dump($form->isSubmitted());
22+
dump($form->isValid());
23+
dump($form->getErrors(true));
24+
1625
// replace this example code with whatever you need
1726
return $this->render('default/index.html.twig', [
1827
'base_dir' => realpath($this->getParameter('kernel.root_dir').'/..').DIRECTORY_SEPARATOR,
1928
]);
29+
2030
}
2131
}

src/AppBundle/Entity/Test.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace AppBundle\Entity;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
use Symfony\Component\Validator\Constraints as Assert;
7+
8+
9+
class Test {
10+
11+
private $url;
12+
13+
/**
14+
* Set url
15+
*
16+
* @param string $url
17+
*
18+
* @return Test
19+
*/
20+
public function setUrl($url) {
21+
$this->url = $url;
22+
23+
return $this;
24+
}
25+
26+
/**
27+
* Get url
28+
*
29+
* @return string
30+
*/
31+
public function getUrl() {
32+
return $this->url;
33+
}
34+
35+
/**
36+
* @Assert\IsTrue()
37+
*/
38+
public function isUrl() {
39+
return true;
40+
}
41+
42+
}

src/AppBundle/Form/TestType.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace AppBundle\Form;
4+
5+
use Symfony\Component\Form\AbstractType;
6+
use Symfony\Component\Form\Extension\Core\Type\TextType;
7+
use Symfony\Component\Form\FormBuilderInterface;
8+
use Symfony\Component\OptionsResolver\OptionsResolver;
9+
10+
class TestType extends AbstractType {
11+
12+
/**
13+
* @param FormBuilderInterface $builder
14+
* @param array $options
15+
*/
16+
public function buildForm(FormBuilderInterface $builder, array $options) {
17+
$builder
18+
->add('url',TextType::class)
19+
;
20+
}
21+
22+
/**
23+
* @param OptionsResolver $resolver
24+
*/
25+
public function configureOptions(OptionsResolver $resolver) {
26+
$resolver->setDefaults(array(
27+
'data_class' => 'AppBundle\Entity\Test'
28+
));
29+
}
30+
31+
}

0 commit comments

Comments
 (0)
0