Skip to content

Commit 4e3ecb0

Browse files
author
Jhonny Lidfors
committed
Update cookbook entries with best practices
1 parent 653b6d4 commit 4e3ecb0

18 files changed

+166
-167
lines changed

cookbook/doctrine/event_listeners_subscribers.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ managers that use this connection.
4242
4343
services:
4444
my.listener:
45-
class: Acme\SearchBundle\EventListener\SearchIndexer
45+
class: AppBundle\EventListener\SearchIndexer
4646
tags:
4747
- { name: doctrine.event_listener, event: postPersist }
4848
my.listener2:
49-
class: Acme\SearchBundle\EventListener\SearchIndexer2
49+
class: AppBundle\EventListener\SearchIndexer2
5050
tags:
5151
- { name: doctrine.event_listener, event: postPersist, connection: default }
5252
my.subscriber:
53-
class: Acme\SearchBundle\EventListener\SearchIndexerSubscriber
53+
class: AppBundle\EventListener\SearchIndexerSubscriber
5454
tags:
5555
- { name: doctrine.event_subscriber, connection: default }
5656
@@ -67,13 +67,13 @@ managers that use this connection.
6767
</doctrine:config>
6868
6969
<services>
70-
<service id="my.listener" class="Acme\SearchBundle\EventListener\SearchIndexer">
70+
<service id="my.listener" class="AppBundle\EventListener\SearchIndexer">
7171
<tag name="doctrine.event_listener" event="postPersist" />
7272
</service>
73-
<service id="my.listener2" class="Acme\SearchBundle\EventListener\SearchIndexer2">
73+
<service id="my.listener2" class="AppBundle\EventListener\SearchIndexer2">
7474
<tag name="doctrine.event_listener" event="postPersist" connection="default" />
7575
</service>
76-
<service id="my.subscriber" class="Acme\SearchBundle\EventListener\SearchIndexerSubscriber">
76+
<service id="my.subscriber" class="AppBundle\EventListener\SearchIndexerSubscriber">
7777
<tag name="doctrine.event_subscriber" connection="default" />
7878
</service>
7979
</services>
@@ -98,21 +98,21 @@ managers that use this connection.
9898
$container
9999
->setDefinition(
100100
'my.listener',
101-
new Definition('Acme\SearchBundle\EventListener\SearchIndexer')
101+
new Definition('AppBundle\EventListener\SearchIndexer')
102102
)
103103
->addTag('doctrine.event_listener', array('event' => 'postPersist'))
104104
;
105105
$container
106106
->setDefinition(
107107
'my.listener2',
108-
new Definition('Acme\SearchBundle\EventListener\SearchIndexer2')
108+
new Definition('AppBundle\EventListener\SearchIndexer2')
109109
)
110110
->addTag('doctrine.event_listener', array('event' => 'postPersist', 'connection' => 'default'))
111111
;
112112
$container
113113
->setDefinition(
114114
'my.subscriber',
115-
new Definition('Acme\SearchBundle\EventListener\SearchIndexerSubscriber')
115+
new Definition('AppBundle\EventListener\SearchIndexerSubscriber')
116116
)
117117
->addTag('doctrine.event_subscriber', array('connection' => 'default'))
118118
;
@@ -124,11 +124,11 @@ In the previous example, a service ``my.listener`` was configured as a Doctrine
124124
listener on the event ``postPersist``. The class behind that service must have
125125
a ``postPersist`` method, which will be called when the event is dispatched::
126126

127-
// src/Acme/SearchBundle/EventListener/SearchIndexer.php
128-
namespace Acme\SearchBundle\EventListener;
127+
// src/AppBundle/EventListener/SearchIndexer.php
128+
namespace AppBundle\EventListener;
129129

130130
use Doctrine\ORM\Event\LifecycleEventArgs;
131-
use Acme\StoreBundle\Entity\Product;
131+
use AppBundle\Entity\Product;
132132

133133
class SearchIndexer
134134
{
@@ -160,13 +160,13 @@ Creating the Subscriber Class
160160
A Doctrine event subscriber must implement the ``Doctrine\Common\EventSubscriber``
161161
interface and have an event method for each event it subscribes to::
162162

163-
// src/Acme/SearchBundle/EventListener/SearchIndexerSubscriber.php
164-
namespace Acme\SearchBundle\EventListener;
163+
// src/AppBundle/EventListener/SearchIndexerSubscriber.php
164+
namespace AppBundle\EventListener;
165165

166166
use Doctrine\Common\EventSubscriber;
167167
use Doctrine\ORM\Event\LifecycleEventArgs;
168168
// for Doctrine 2.4: Doctrine\Common\Persistence\Event\LifecycleEventArgs;
169-
use Acme\StoreBundle\Entity\Product;
169+
use AppBundle\Entity\Product;
170170

171171
class SearchIndexerSubscriber implements EventSubscriber
172172
{

cookbook/doctrine/file_uploads.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ rules::
207207
.. code-block:: php
208208
209209
// src/AppBundle/Entity/Document.php
210-
namespace Acme\DemoBundle\Entity;
210+
namespace AppBundle\Entity;
211211
212212
// ...
213213
use Symfony\Component\Validator\Mapping\ClassMetadata;

cookbook/doctrine/registration_form.rst

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ The simple User Model
1515

1616
You have a simple ``User`` entity mapped to the database::
1717

18-
// src/Acme/AccountBundle/Entity/User.php
19-
namespace Acme\AccountBundle\Entity;
18+
// src/AppBundle/Entity/User.php
19+
namespace AppBundle\Entity;
2020

2121
use Doctrine\ORM\Mapping as ORM;
2222
use Symfony\Component\Validator\Constraints as Assert;
@@ -106,8 +106,8 @@ Create a Form for the Model
106106

107107
Next, create the form for the ``User`` model::
108108

109-
// src/Acme/AccountBundle/Form/Type/UserType.php
110-
namespace Acme\AccountBundle\Form\Type;
109+
// src/AppBundle/Form/Type/UserType.php
110+
namespace AppBundle\Form\Type;
111111

112112
use Symfony\Component\Form\AbstractType;
113113
use Symfony\Component\Form\FormBuilderInterface;
@@ -128,7 +128,7 @@ Next, create the form for the ``User`` model::
128128
public function setDefaultOptions(OptionsResolverInterface $resolver)
129129
{
130130
$resolver->setDefaults(array(
131-
'data_class' => 'Acme\AccountBundle\Entity\User'
131+
'data_class' => 'AppBundle\Entity\User'
132132
));
133133
}
134134

@@ -156,17 +156,17 @@ be stored in the database.
156156

157157
Start by creating a simple class which represents the "registration"::
158158

159-
// src/Acme/AccountBundle/Form/Model/Registration.php
160-
namespace Acme\AccountBundle\Form\Model;
159+
// src/AppBundle/Form/Model/Registration.php
160+
namespace AppBundle\Form\Model;
161161

162162
use Symfony\Component\Validator\Constraints as Assert;
163163

164-
use Acme\AccountBundle\Entity\User;
164+
use AppBundle\Entity\User;
165165

166166
class Registration
167167
{
168168
/**
169-
* @Assert\Type(type="Acme\AccountBundle\Entity\User")
169+
* @Assert\Type(type="AppBundle\Entity\User")
170170
* @Assert\Valid()
171171
*/
172172
protected $user;
@@ -200,8 +200,8 @@ Start by creating a simple class which represents the "registration"::
200200

201201
Next, create the form for this ``Registration`` model::
202202

203-
// src/Acme/AccountBundle/Form/Type/RegistrationType.php
204-
namespace Acme\AccountBundle\Form\Type;
203+
// src/AppBundle/Form/Type/RegistrationType.php
204+
namespace AppBundle\Form\Type;
205205

206206
use Symfony\Component\Form\AbstractType;
207207
use Symfony\Component\Form\FormBuilderInterface;
@@ -236,13 +236,13 @@ Handling the Form Submission
236236
Next, you need a controller to handle the form. Start by creating a simple
237237
controller for displaying the registration form::
238238

239-
// src/Acme/AccountBundle/Controller/AccountController.php
240-
namespace Acme\AccountBundle\Controller;
239+
// src/AppBundle/Controller/AccountController.php
240+
namespace AppBundle\Controller;
241241

242242
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
243243

244-
use Acme\AccountBundle\Form\Type\RegistrationType;
245-
use Acme\AccountBundle\Form\Model\Registration;
244+
use AppBundle\Form\Type\RegistrationType;
245+
use AppBundle\Form\Model\Registration;
246246

247247
class AccountController extends Controller
248248
{
@@ -254,7 +254,7 @@ controller for displaying the registration form::
254254
));
255255

256256
return $this->render(
257-
'AcmeAccountBundle:Account:register.html.twig',
257+
'AppBundle:Account:register.html.twig',
258258
array('form' => $form->createView())
259259
);
260260
}
@@ -264,7 +264,7 @@ And its template:
264264

265265
.. code-block:: html+jinja
266266

267-
{# src/Acme/AccountBundle/Resources/views/Account/register.html.twig #}
267+
{# src/AppBundle/Resources/views/Account/register.html.twig #}
268268
{{ form(form) }}
269269

270270
Next, create the controller which handles the form submission. This performs
@@ -291,7 +291,7 @@ the validation and saves the data into the database::
291291
}
292292

293293
return $this->render(
294-
'AcmeAccountBundle:Account:register.html.twig',
294+
'AppBundle:Account:register.html.twig',
295295
array('form' => $form->createView())
296296
);
297297
}
@@ -307,44 +307,44 @@ Next, update your routes. If you're placing your routes inside your bundle
307307

308308
.. code-block:: yaml
309309
310-
# src/Acme/AccountBundle/Resources/config/routing.yml
310+
# src/AppBundle/Resources/config/routing.yml
311311
account_register:
312312
path: /register
313-
defaults: { _controller: AcmeAccountBundle:Account:register }
313+
defaults: { _controller: AppBundle:Account:register }
314314
315315
account_create:
316316
path: /register/create
317-
defaults: { _controller: AcmeAccountBundle:Account:create }
317+
defaults: { _controller: AppBundle:Account:create }
318318
319319
.. code-block:: xml
320320
321-
<!-- src/Acme/AccountBundle/Resources/config/routing.xml -->
321+
<!-- src/AppBundle/Resources/config/routing.xml -->
322322
<?xml version="1.0" encoding="UTF-8" ?>
323323
<routes xmlns="http://symfony.com/schema/routing"
324324
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
325325
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
326326
327327
<route id="account_register" path="/register">
328-
<default key="_controller">AcmeAccountBundle:Account:register</default>
328+
<default key="_controller">AppBundle:Account:register</default>
329329
</route>
330330
331331
<route id="account_create" path="/register/create">
332-
<default key="_controller">AcmeAccountBundle:Account:create</default>
332+
<default key="_controller">AppBundle:Account:create</default>
333333
</route>
334334
</routes>
335335
336336
.. code-block:: php
337337
338-
// src/Acme/AccountBundle/Resources/config/routing.php
338+
// src/AppBundle/Resources/config/routing.php
339339
use Symfony\Component\Routing\RouteCollection;
340340
use Symfony\Component\Routing\Route;
341341
342342
$collection = new RouteCollection();
343343
$collection->add('account_register', new Route('/register', array(
344-
'_controller' => 'AcmeAccountBundle:Account:register',
344+
'_controller' => 'AppBundle:Account:register',
345345
)));
346346
$collection->add('account_create', new Route('/register/create', array(
347-
'_controller' => 'AcmeAccountBundle:Account:create',
347+
'_controller' => 'AppBundle:Account:create',
348348
)));
349349
350350
return $collection;

cookbook/form/create_custom_field_type.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ the ``genders`` parameter value as the first argument to its to-be-created
303303
304304
# src/AppBundle/Resources/config/services.yml
305305
services:
306-
acme_demo.form.type.gender:
306+
app.form.type.gender:
307307
class: AppBundle\Form\Type\GenderType
308308
arguments:
309309
- "%genders%"
@@ -313,7 +313,7 @@ the ``genders`` parameter value as the first argument to its to-be-created
313313
.. code-block:: xml
314314
315315
<!-- src/AppBundle/Resources/config/services.xml -->
316-
<service id="acme_demo.form.type.gender" class="AppBundle\Form\Type\GenderType">
316+
<service id="app.form.type.gender" class="AppBundle\Form\Type\GenderType">
317317
<argument>%genders%</argument>
318318
<tag name="form.type" alias="gender" />
319319
</service>
@@ -324,7 +324,7 @@ the ``genders`` parameter value as the first argument to its to-be-created
324324
use Symfony\Component\DependencyInjection\Definition;
325325
326326
$container
327-
->setDefinition('acme_demo.form.type.gender', new Definition(
327+
->setDefinition('app.form.type.gender', new Definition(
328328
'AppBundle\Form\Type\GenderType',
329329
array('%genders%')
330330
))

cookbook/form/create_form_type_extension.rst

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ When creating a form type extension, you can either implement the
4848
or extend the :class:`Symfony\\Component\\Form\\AbstractTypeExtension`
4949
class. In most cases, it's easier to extend the abstract class::
5050

51-
// src/Acme/DemoBundle/Form/Extension/ImageTypeExtension.php
52-
namespace Acme\DemoBundle\Form\Extension;
51+
// src/AppBundle/Form/Extension/ImageTypeExtension.php
52+
namespace AppBundle\Form\Extension;
5353

5454
use Symfony\Component\Form\AbstractTypeExtension;
5555

@@ -103,15 +103,15 @@ tag:
103103
.. code-block:: yaml
104104
105105
services:
106-
acme_demo_bundle.image_type_extension:
107-
class: Acme\DemoBundle\Form\Extension\ImageTypeExtension
106+
app.image_type_extension:
107+
class: AppBundle\Form\Extension\ImageTypeExtension
108108
tags:
109109
- { name: form.type_extension, alias: file }
110110
111111
.. code-block:: xml
112112
113-
<service id="acme_demo_bundle.image_type_extension"
114-
class="Acme\DemoBundle\Form\Extension\ImageTypeExtension"
113+
<service id="app.image_type_extension"
114+
class="AppBundle\Form\Extension\ImageTypeExtension"
115115
>
116116
<tag name="form.type_extension" alias="file" />
117117
</service>
@@ -120,8 +120,8 @@ tag:
120120
121121
$container
122122
->register(
123-
'acme_demo_bundle.image_type_extension',
124-
'Acme\DemoBundle\Form\Extension\ImageTypeExtension'
123+
'app.image_type_extension',
124+
'AppBundle\Form\Extension\ImageTypeExtension'
125125
)
126126
->addTag('form.type_extension', array('alias' => 'file'));
127127
@@ -140,8 +140,8 @@ you have a Media model with a file property (corresponding to the file field
140140
in the form) and a path property (corresponding to the image path in the
141141
database)::
142142

143-
// src/Acme/DemoBundle/Entity/Media.php
144-
namespace Acme\DemoBundle\Entity;
143+
// src/AppBundle/Entity/Media.php
144+
namespace AppBundle\Entity;
145145

146146
use Symfony\Component\Validator\Constraints as Assert;
147147

@@ -188,8 +188,8 @@ you will be able to specify a new option: ``image_path``. This option will
188188
tell the file field how to get the actual image URL in order to display
189189
it in the view::
190190

191-
// src/Acme/DemoBundle/Form/Extension/ImageTypeExtension.php
192-
namespace Acme\DemoBundle\Form\Extension;
191+
// src/AppBundle/Form/Extension/ImageTypeExtension.php
192+
namespace AppBundle\Form\Extension;
193193

194194
use Symfony\Component\Form\AbstractTypeExtension;
195195
use Symfony\Component\Form\FormView;
@@ -260,7 +260,7 @@ Specifically, you need to override the ``file_widget`` block:
260260

261261
.. code-block:: html+jinja
262262

263-
{# src/Acme/DemoBundle/Resources/views/Form/fields.html.twig #}
263+
{# src/AppBundle/Resources/views/Form/fields.html.twig #}
264264
{% extends 'form_div_layout.html.twig' %}
265265

266266
{% block file_widget %}
@@ -276,7 +276,7 @@ Specifically, you need to override the ``file_widget`` block:
276276

277277
.. code-block:: html+php
278278

279-
<!-- src/Acme/DemoBundle/Resources/views/Form/file_widget.html.php -->
279+
<!-- src/AppBundle/Resources/views/Form/file_widget.html.php -->
280280
<?php echo $view['form']->widget($form) ?>
281281
<?php if (null !== $image_url): ?>
282282
<img src="<?php echo $view['assets']->getUrl($image_url) ?>"/>
@@ -296,8 +296,8 @@ From now on, when adding a field of type ``file`` in your form, you can
296296
specify an ``image_path`` option that will be used to display an image
297297
next to the file field. For example::
298298

299-
// src/Acme/DemoBundle/Form/Type/MediaType.php
300-
namespace Acme\DemoBundle\Form\Type;
299+
// src/AppBundle/Form/Type/MediaType.php
300+
namespace AppBundle\Form\Type;
301301

302302
use Symfony\Component\Form\AbstractType;
303303
use Symfony\Component\Form\FormBuilderInterface;

0 commit comments

Comments
 (0)