@@ -1011,6 +1011,9 @@ In :ref:`book-form-creating-form-classes` you will learn how to move the
1011
1011
form building code into separate classes. When using an external form class
1012
1012
in the controller, you can pass the action and method as form options::
1013
1013
1014
+ use AppBundle\Form\TaskType;
1015
+ // ...
1016
+
1014
1017
$form = $this->createForm(new TaskType(), $task, array(
1015
1018
'action' => $this->generateUrl('target_route'),
1016
1019
'method' => 'GET',
@@ -1056,8 +1059,8 @@ However, a better practice is to build the form in a separate, standalone PHP
1056
1059
class, which can then be reused anywhere in your application. Create a new class
1057
1060
that will house the logic for building the task form::
1058
1061
1059
- // src/AppBundle/Form/Type/ TaskType.php
1060
- namespace AppBundle\Form\Type ;
1062
+ // src/AppBundle/Form/TaskType.php
1063
+ namespace AppBundle\Form;
1061
1064
1062
1065
use Symfony\Component\Form\AbstractType;
1063
1066
use Symfony\Component\Form\FormBuilderInterface;
@@ -1093,7 +1096,7 @@ be used to quickly build a form object in the controller::
1093
1096
// src/AppBundle/Controller/DefaultController.php
1094
1097
1095
1098
// add this new use statement at the top of the class
1096
- use AppBundle\Form\Type\ TaskType;
1099
+ use AppBundle\Form\TaskType;
1097
1100
1098
1101
public function newAction()
1099
1102
{
@@ -1181,7 +1184,7 @@ easy to use in your application.
1181
1184
# src/AppBundle/Resources/config/services.yml
1182
1185
services :
1183
1186
app.form.type.task :
1184
- class : AppBundle\Form\Type\ TaskType
1187
+ class : AppBundle\Form\TaskType
1185
1188
tags :
1186
1189
- { name: form.type, alias: app_task }
1187
1190
@@ -1194,7 +1197,7 @@ easy to use in your application.
1194
1197
xsi : schemaLocation =" http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd" >
1195
1198
1196
1199
<services >
1197
- <service id =" app.form.type.task" class =" AppBundle\Form\Type\ TaskType" >
1200
+ <service id =" app.form.type.task" class =" AppBundle\Form\TaskType" >
1198
1201
<tag name =" form.type" alias =" app_task" />
1199
1202
</service >
1200
1203
</services >
@@ -1206,7 +1209,7 @@ easy to use in your application.
1206
1209
$container
1207
1210
->register(
1208
1211
'app.form.type.task',
1209
- 'AppBundle\Form\Type\ TaskType'
1212
+ 'AppBundle\Form\TaskType'
1210
1213
)
1211
1214
->addTag('form.type', array(
1212
1215
'alias' => 'app_task',
@@ -1345,8 +1348,8 @@ Next, add a new ``category`` property to the ``Task`` class::
1345
1348
Now that your application has been updated to reflect the new requirements,
1346
1349
create a form class so that a ``Category `` object can be modified by the user::
1347
1350
1348
- // src/AppBundle/Form/Type/ CategoryType.php
1349
- namespace AppBundle\Form\Type ;
1351
+ // src/AppBundle/Form/CategoryType.php
1352
+ namespace AppBundle\Form;
1350
1353
1351
1354
use Symfony\Component\Form\AbstractType;
1352
1355
use Symfony\Component\Form\FormBuilderInterface;
@@ -1375,11 +1378,10 @@ create a form class so that a ``Category`` object can be modified by the user::
1375
1378
The end goal is to allow the ``Category `` of a ``Task `` to be modified right
1376
1379
inside the task form itself. To accomplish this, add a ``category `` field
1377
1380
to the ``TaskType `` object whose type is an instance of the new ``CategoryType ``
1378
- class:
1379
-
1380
- .. code-block :: php
1381
+ class::
1381
1382
1382
1383
use Symfony\Component\Form\FormBuilderInterface;
1384
+ use AppBundle\Form\CategoryType;
1383
1385
1384
1386
public function buildForm(FormBuilderInterface $builder, array $options)
1385
1387
{
0 commit comments