Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cookbook entries with best practices #5674

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions cookbook/doctrine/event_listeners_subscribers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ managers that use this connection.

services:
my.listener:
class: Acme\SearchBundle\EventListener\SearchIndexer
class: AppBundle\EventListener\SearchIndexer
tags:
- { name: doctrine.event_listener, event: postPersist }
my.listener2:
class: Acme\SearchBundle\EventListener\SearchIndexer2
class: AppBundle\EventListener\SearchIndexer2
tags:
- { name: doctrine.event_listener, event: postPersist, connection: default }
my.subscriber:
class: Acme\SearchBundle\EventListener\SearchIndexerSubscriber
class: AppBundle\EventListener\SearchIndexerSubscriber
tags:
- { name: doctrine.event_subscriber, connection: default }

Expand All @@ -67,13 +67,13 @@ managers that use this connection.
</doctrine:config>

<services>
<service id="my.listener" class="Acme\SearchBundle\EventListener\SearchIndexer">
<service id="my.listener" class="AppBundle\EventListener\SearchIndexer">
<tag name="doctrine.event_listener" event="postPersist" />
</service>
<service id="my.listener2" class="Acme\SearchBundle\EventListener\SearchIndexer2">
<service id="my.listener2" class="AppBundle\EventListener\SearchIndexer2">
<tag name="doctrine.event_listener" event="postPersist" connection="default" />
</service>
<service id="my.subscriber" class="Acme\SearchBundle\EventListener\SearchIndexerSubscriber">
<service id="my.subscriber" class="AppBundle\EventListener\SearchIndexerSubscriber">
<tag name="doctrine.event_subscriber" connection="default" />
</service>
</services>
Expand All @@ -98,21 +98,21 @@ managers that use this connection.
$container
->setDefinition(
'my.listener',
new Definition('Acme\SearchBundle\EventListener\SearchIndexer')
new Definition('AppBundle\EventListener\SearchIndexer')
)
->addTag('doctrine.event_listener', array('event' => 'postPersist'))
;
$container
->setDefinition(
'my.listener2',
new Definition('Acme\SearchBundle\EventListener\SearchIndexer2')
new Definition('AppBundle\EventListener\SearchIndexer2')
)
->addTag('doctrine.event_listener', array('event' => 'postPersist', 'connection' => 'default'))
;
$container
->setDefinition(
'my.subscriber',
new Definition('Acme\SearchBundle\EventListener\SearchIndexerSubscriber')
new Definition('AppBundle\EventListener\SearchIndexerSubscriber')
)
->addTag('doctrine.event_subscriber', array('connection' => 'default'))
;
Expand All @@ -124,11 +124,11 @@ In the previous example, a service ``my.listener`` was configured as a Doctrine
listener on the event ``postPersist``. The class behind that service must have
a ``postPersist`` method, which will be called when the event is dispatched::

// src/Acme/SearchBundle/EventListener/SearchIndexer.php
namespace Acme\SearchBundle\EventListener;
// src/AppBundle/EventListener/SearchIndexer.php
namespace AppBundle\EventListener;

use Doctrine\ORM\Event\LifecycleEventArgs;
use Acme\StoreBundle\Entity\Product;
use AppBundle\Entity\Product;

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

// src/Acme/SearchBundle/EventListener/SearchIndexerSubscriber.php
namespace Acme\SearchBundle\EventListener;
// src/AppBundle/EventListener/SearchIndexerSubscriber.php
namespace AppBundle\EventListener;

use Doctrine\Common\EventSubscriber;
use Doctrine\ORM\Event\LifecycleEventArgs;
// for Doctrine 2.4: Doctrine\Common\Persistence\Event\LifecycleEventArgs;
use Acme\StoreBundle\Entity\Product;
use AppBundle\Entity\Product;

class SearchIndexerSubscriber implements EventSubscriber
{
Expand Down
2 changes: 1 addition & 1 deletion cookbook/doctrine/file_uploads.rst
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ rules::
.. code-block:: php

// src/AppBundle/Entity/Document.php
namespace Acme\DemoBundle\Entity;
namespace AppBundle\Entity;

// ...
use Symfony\Component\Validator\Mapping\ClassMetadata;
Expand Down
54 changes: 27 additions & 27 deletions cookbook/doctrine/registration_form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ The simple User Model

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

// src/Acme/AccountBundle/Entity/User.php
namespace Acme\AccountBundle\Entity;
// src/AppBundle/Entity/User.php
namespace AppBundle\Entity;

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

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

// src/Acme/AccountBundle/Form/Type/UserType.php
namespace Acme\AccountBundle\Form\Type;
// src/AppBundle/Form/Type/UserType.php
namespace AppBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
Expand All @@ -128,7 +128,7 @@ Next, create the form for the ``User`` model::
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Acme\AccountBundle\Entity\User'
'data_class' => 'AppBundle\Entity\User'
));
}

Expand Down Expand Up @@ -156,17 +156,17 @@ be stored in the database.

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

// src/Acme/AccountBundle/Form/Model/Registration.php
namespace Acme\AccountBundle\Form\Model;
// src/AppBundle/Form/Model/Registration.php
namespace AppBundle\Form\Model;

use Symfony\Component\Validator\Constraints as Assert;

use Acme\AccountBundle\Entity\User;
use AppBundle\Entity\User;

class Registration
{
/**
* @Assert\Type(type="Acme\AccountBundle\Entity\User")
* @Assert\Type(type="AppBundle\Entity\User")
* @Assert\Valid()
*/
protected $user;
Expand Down Expand Up @@ -200,8 +200,8 @@ Start by creating a simple class which represents the "registration"::

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

// src/Acme/AccountBundle/Form/Type/RegistrationType.php
namespace Acme\AccountBundle\Form\Type;
// src/AppBundle/Form/Type/RegistrationType.php
namespace AppBundle\Form\Type;

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

// src/Acme/AccountBundle/Controller/AccountController.php
namespace Acme\AccountBundle\Controller;
// src/AppBundle/Controller/AccountController.php
namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use Acme\AccountBundle\Form\Type\RegistrationType;
use Acme\AccountBundle\Form\Model\Registration;
use AppBundle\Form\Type\RegistrationType;
use AppBundle\Form\Model\Registration;

class AccountController extends Controller
{
Expand All @@ -254,7 +254,7 @@ controller for displaying the registration form::
));

return $this->render(
'AcmeAccountBundle:Account:register.html.twig',
'AppBundle:Account:register.html.twig',
array('form' => $form->createView())
);
}
Expand All @@ -264,7 +264,7 @@ And its template:

.. code-block:: html+jinja

{# src/Acme/AccountBundle/Resources/views/Account/register.html.twig #}
{# src/AppBundle/Resources/views/Account/register.html.twig #}
{{ form(form) }}

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

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

.. code-block:: yaml

# src/Acme/AccountBundle/Resources/config/routing.yml
# src/AppBundle/Resources/config/routing.yml
account_register:
path: /register
defaults: { _controller: AcmeAccountBundle:Account:register }
defaults: { _controller: AppBundle:Account:register }

account_create:
path: /register/create
defaults: { _controller: AcmeAccountBundle:Account:create }
defaults: { _controller: AppBundle:Account:create }

.. code-block:: xml

<!-- src/Acme/AccountBundle/Resources/config/routing.xml -->
<!-- src/AppBundle/Resources/config/routing.xml -->
<?xml version="1.0" encoding="UTF-8" ?>
<routes xmlns="http://symfony.com/schema/routing"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">

<route id="account_register" path="/register">
<default key="_controller">AcmeAccountBundle:Account:register</default>
<default key="_controller">AppBundle:Account:register</default>
</route>

<route id="account_create" path="/register/create">
<default key="_controller">AcmeAccountBundle:Account:create</default>
<default key="_controller">AppBundle:Account:create</default>
</route>
</routes>

.. code-block:: php

// src/Acme/AccountBundle/Resources/config/routing.php
// src/AppBundle/Resources/config/routing.php
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;

$collection = new RouteCollection();
$collection->add('account_register', new Route('/register', array(
'_controller' => 'AcmeAccountBundle:Account:register',
'_controller' => 'AppBundle:Account:register',
)));
$collection->add('account_create', new Route('/register/create', array(
'_controller' => 'AcmeAccountBundle:Account:create',
'_controller' => 'AppBundle:Account:create',
)));

return $collection;
Expand Down
6 changes: 3 additions & 3 deletions cookbook/form/create_custom_field_type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ the ``genders`` parameter value as the first argument to its to-be-created

# src/AppBundle/Resources/config/services.yml
services:
acme_demo.form.type.gender:
app.form.type.gender:
class: AppBundle\Form\Type\GenderType
arguments:
- "%genders%"
Expand All @@ -313,7 +313,7 @@ the ``genders`` parameter value as the first argument to its to-be-created
.. code-block:: xml

<!-- src/AppBundle/Resources/config/services.xml -->
<service id="acme_demo.form.type.gender" class="AppBundle\Form\Type\GenderType">
<service id="app.form.type.gender" class="AppBundle\Form\Type\GenderType">
<argument>%genders%</argument>
<tag name="form.type" alias="gender" />
</service>
Expand All @@ -324,7 +324,7 @@ the ``genders`` parameter value as the first argument to its to-be-created
use Symfony\Component\DependencyInjection\Definition;

$container
->setDefinition('acme_demo.form.type.gender', new Definition(
->setDefinition('app.form.type.gender', new Definition(
'AppBundle\Form\Type\GenderType',
array('%genders%')
))
Expand Down
32 changes: 16 additions & 16 deletions cookbook/form/create_form_type_extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ When creating a form type extension, you can either implement the
or extend the :class:`Symfony\\Component\\Form\\AbstractTypeExtension`
class. In most cases, it's easier to extend the abstract class::

// src/Acme/DemoBundle/Form/Extension/ImageTypeExtension.php
namespace Acme\DemoBundle\Form\Extension;
// src/AppBundle/Form/Extension/ImageTypeExtension.php
namespace AppBundle\Form\Extension;

use Symfony\Component\Form\AbstractTypeExtension;

Expand Down Expand Up @@ -103,15 +103,15 @@ tag:
.. code-block:: yaml

services:
acme_demo_bundle.image_type_extension:
class: Acme\DemoBundle\Form\Extension\ImageTypeExtension
app.image_type_extension:
class: AppBundle\Form\Extension\ImageTypeExtension
tags:
- { name: form.type_extension, alias: file }

.. code-block:: xml

<service id="acme_demo_bundle.image_type_extension"
class="Acme\DemoBundle\Form\Extension\ImageTypeExtension"
<service id="app.image_type_extension"
class="AppBundle\Form\Extension\ImageTypeExtension"
>
<tag name="form.type_extension" alias="file" />
</service>
Expand All @@ -120,8 +120,8 @@ tag:

$container
->register(
'acme_demo_bundle.image_type_extension',
'Acme\DemoBundle\Form\Extension\ImageTypeExtension'
'app.image_type_extension',
'AppBundle\Form\Extension\ImageTypeExtension'
)
->addTag('form.type_extension', array('alias' => 'file'));

Expand All @@ -140,8 +140,8 @@ you have a Media model with a file property (corresponding to the file field
in the form) and a path property (corresponding to the image path in the
database)::

// src/Acme/DemoBundle/Entity/Media.php
namespace Acme\DemoBundle\Entity;
// src/AppBundle/Entity/Media.php
namespace AppBundle\Entity;

use Symfony\Component\Validator\Constraints as Assert;

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

// src/Acme/DemoBundle/Form/Extension/ImageTypeExtension.php
namespace Acme\DemoBundle\Form\Extension;
// src/AppBundle/Form/Extension/ImageTypeExtension.php
namespace AppBundle\Form\Extension;

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

.. code-block:: html+jinja

{# src/Acme/DemoBundle/Resources/views/Form/fields.html.twig #}
{# src/AppBundle/Resources/views/Form/fields.html.twig #}
{% extends 'form_div_layout.html.twig' %}

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

.. code-block:: html+php

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

// src/Acme/DemoBundle/Form/Type/MediaType.php
namespace Acme\DemoBundle\Form\Type;
// src/AppBundle/Form/Type/MediaType.php
namespace AppBundle\Form\Type;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
Expand Down
Loading