Skip to content

Commit 5adc91c

Browse files
committed
Revert "minor #6479 Update php.rst (carlos-granados)"
This reverts commit fefc8a0, reversing changes made to 7819f9e.
1 parent 1653948 commit 5adc91c

File tree

406 files changed

+5728
-17256
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

406 files changed

+5728
-17256
lines changed

Diff for: best_practices/business-logic.rst

+1-5
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ Inside here, you can create whatever directories you want to organize things:
2121
│ └─ AppBundle/
2222
│ └─ Utils/
2323
│ └─ MyClass.php
24-
├─ tests/
25-
├─ var/
2624
├─ vendor/
2725
└─ web/
2826
@@ -42,8 +40,6 @@ and put things there:
4240
│ │ └─ Utils/
4341
│ │ └─ MyClass.php
4442
│ └─ AppBundle/
45-
├─ tests/
46-
├─ var/
4743
├─ vendor/
4844
└─ web/
4945
@@ -322,7 +318,7 @@ command:
322318

323319
.. code-block:: bash
324320
325-
$ php bin/console doctrine:fixtures:load
321+
$ php app/console doctrine:fixtures:load
326322
327323
Careful, database will be purged. Do you want to continue Y/N ? Y
328324
> purging database

Diff for: best_practices/configuration.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ Canonical Parameters
5252
Define all your application's parameters in the
5353
``app/config/parameters.yml.dist`` file.
5454

55-
Symfony includes a configuration file called ``parameters.yml.dist``, which
56-
stores the canonical list of configuration parameters for the application.
55+
Since version 2.3, Symfony includes a configuration file called ``parameters.yml.dist``,
56+
which stores the canonical list of configuration parameters for the application.
5757

5858
Whenever a new configuration parameter is defined for the application, you
5959
should also add it to this file and submit the changes to your version control

Diff for: best_practices/creating-the-project.rst

+33-23
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ to create files and execute the following commands:
2727

2828
.. code-block:: bash
2929
30+
# Linux, Mac OS X
3031
$ cd projects/
3132
$ symfony new blog
3233
@@ -62,35 +63,27 @@ number of files and directories generated automatically:
6263
6364
blog/
6465
├─ app/
66+
│ ├─ console
67+
│ ├─ cache/
6568
│ ├─ config/
69+
│ ├─ logs/
6670
│ └─ Resources/
67-
├─ bin
68-
│ └─ console
6971
├─ src/
7072
│ └─ AppBundle/
71-
├─ var/
72-
│ ├─ cache/
73-
│ ├─ logs/
74-
│ └─ sessions/
75-
├─ tests/
76-
│ └─ AppBundle/
7773
├─ vendor/
7874
└─ web/
7975
8076
This file and directory hierarchy is the convention proposed by Symfony to
8177
structure your applications. The recommended purpose of each directory is the
8278
following:
8379

80+
* ``app/cache/``, stores all the cache files generated by the application;
8481
* ``app/config/``, stores all the configuration defined for any environment;
82+
* ``app/logs/``, stores all the log files generated by the application;
8583
* ``app/Resources/``, stores all the templates and the translation files for the
8684
application;
8785
* ``src/AppBundle/``, stores the Symfony specific code (controllers and routes),
8886
your domain code (e.g. Doctrine classes) and all your business logic;
89-
* ``var/cache/``, stores all the cache files generated by the application;
90-
* ``var/logs/``, stores all the log files generated by the application;
91-
* ``var/sessions/``, stores all the session files generated by the application;
92-
* ``tests/AppBundle/``, stores the automatic tests (e.g. Unit tests) of the
93-
application.
9487
* ``vendor/``, this is the directory where Composer installs the application's
9588
dependencies and you should never modify any of its contents;
9689
* ``web/``, stores all the front controller files and all the web assets, such
@@ -114,7 +107,8 @@ ProductBundle, then there's no advantage to having two separate bundles.
114107
Create only one bundle called AppBundle for your application logic.
115108

116109
Implementing a single AppBundle bundle in your projects will make your code
117-
more concise and easier to understand.
110+
more concise and easier to understand. Starting in Symfony 2.6, the official
111+
Symfony documentation uses the AppBundle name.
118112

119113
.. note::
120114

@@ -134,18 +128,13 @@ that follows these best practices:
134128
135129
blog/
136130
├─ app/
131+
│ ├─ console
132+
│ ├─ cache/
137133
│ ├─ config/
134+
│ ├─ logs/
138135
│ └─ Resources/
139-
├─ bin/
140-
│ └─ console
141136
├─ src/
142137
│ └─ AppBundle/
143-
├─ tests/
144-
│ └─ AppBundle/
145-
├─ var/
146-
│ ├─ cache/
147-
│ ├─ logs/
148-
└─ sessions/
149138
├─ vendor/
150139
└─ web/
151140
├─ app.php
@@ -158,7 +147,7 @@ that follows these best practices:
158147

159148
.. code-block:: bash
160149
161-
$ php bin/console generate:bundle --namespace=AppBundle --dir=src --format=annotation --no-interaction
150+
$ php app/console generate:bundle --namespace=AppBundle --dir=src --format=annotation --no-interaction
162151
163152
Extending the Directory Structure
164153
---------------------------------
@@ -168,6 +157,27 @@ structure of Symfony, you can
168157
:doc:`override the location of the main directories </cookbook/configuration/override_dir_structure>`:
169158
``cache/``, ``logs/`` and ``web/``.
170159

160+
In addition, Symfony3 will use a slightly different directory structure when
161+
it's released:
162+
163+
.. code-block:: text
164+
165+
blog-symfony3/
166+
├─ app/
167+
│ ├─ config/
168+
│ └─ Resources/
169+
├─ bin/
170+
│ └─ console
171+
├─ src/
172+
├─ var/
173+
│ ├─ cache/
174+
│ └─ logs/
175+
├─ vendor/
176+
└─ web/
177+
178+
The changes are pretty superficial, but for now, we recommend that you use
179+
the Symfony directory structure.
180+
171181
.. _`Composer`: https://getcomposer.org/
172182
.. _`Phar extension`: http://php.net/manual/en/intro.phar.php
173183
.. _`public checksums repository`: https://github.com/sensiolabs/checksums

Diff for: best_practices/forms.rst

+44-22
Original file line numberDiff line numberDiff line change
@@ -21,38 +21,40 @@ form in its own PHP class::
2121

2222
use Symfony\Component\Form\AbstractType;
2323
use Symfony\Component\Form\FormBuilderInterface;
24-
use Symfony\Component\OptionsResolver\OptionsResolver;
25-
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
26-
use Symfony\Component\Form\Extension\Core\Type\EmailType;
27-
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
24+
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
2825

2926
class PostType extends AbstractType
3027
{
3128
public function buildForm(FormBuilderInterface $builder, array $options)
3229
{
3330
$builder
3431
->add('title')
35-
->add('summary', TextareaType::class)
36-
->add('content', TextareaType::class)
37-
->add('authorEmail', EmailType::class)
38-
->add('publishedAt', DateTimeType::class)
32+
->add('summary', 'textarea')
33+
->add('content', 'textarea')
34+
->add('authorEmail', 'email')
35+
->add('publishedAt', 'datetime')
3936
;
4037
}
4138

42-
public function configureOptions(OptionsResolver $resolver)
39+
public function setDefaultOptions(OptionsResolverInterface $resolver)
4340
{
4441
$resolver->setDefaults(array(
4542
'data_class' => 'AppBundle\Entity\Post'
4643
));
4744
}
45+
46+
public function getName()
47+
{
48+
return 'post';
49+
}
4850
}
4951

5052
.. best-practice::
5153

5254
Put the form type classes in the ``AppBundle\Form`` namespace, unless you
5355
use other custom form classes like data transformers.
5456

55-
To use the class, use ``createForm()`` and pass the fully qualified class name::
57+
To use the class, use ``createForm()`` and instantiate the new class::
5658

5759
// ...
5860
use AppBundle\Form\PostType;
@@ -61,7 +63,7 @@ To use the class, use ``createForm()`` and pass the fully qualified class name::
6163
public function newAction(Request $request)
6264
{
6365
$post = new Post();
64-
$form = $this->createForm(PostType::class, $post);
66+
$form = $this->createForm(new PostType(), $post);
6567

6668
// ...
6769
}
@@ -71,9 +73,13 @@ Registering Forms as Services
7173

7274
You can also
7375
:ref:`register your form type as a service <form-cookbook-form-field-service>`.
74-
This is only needed if your form type requires some dependencies to be injected
75-
by the container, otherwise it is unnecessary overhead and therefore *not*
76-
recommended to do this for all form type classes.
76+
But this is *not* recommended unless you plan to reuse the new form type in many
77+
places or embed it in other forms directly or via the
78+
:doc:`collection type </reference/forms/types/collection>`.
79+
80+
For most forms that are used only to edit or create something, registering
81+
the form as a service is over-kill, and makes it more difficult to figure
82+
out exactly which form class is being used in a controller.
7783

7884
Form Button Configuration
7985
-------------------------
@@ -85,10 +91,9 @@ makes them easier to re-use later.
8591

8692
Add buttons in the templates, not in the form classes or the controllers.
8793

88-
The Symfony Form component allows you to add buttons as fields on your form.
89-
This is a nice way to simplify the template that renders your form. But if you
90-
add the buttons directly in your form class, this would effectively limit the
91-
scope of that form:
94+
Since Symfony 2.3, you can add buttons as fields on your form. This is a nice
95+
way to simplify the template that renders your form. But if you add the buttons
96+
directly in your form class, this would effectively limit the scope of that form:
9297

9398
.. code-block:: php
9499
@@ -98,7 +103,7 @@ scope of that form:
98103
{
99104
$builder
100105
// ...
101-
->add('save', SubmitType::class, array('label' => 'Create Post'))
106+
->add('save', 'submit', array('label' => 'Create Post'))
102107
;
103108
}
104109
@@ -113,7 +118,6 @@ some developers configure form buttons in the controller::
113118

114119
use Symfony\Component\HttpFoundation\Request;
115120
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
116-
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
117121
use AppBundle\Entity\Post;
118122
use AppBundle\Form\PostType;
119123

@@ -124,8 +128,8 @@ some developers configure form buttons in the controller::
124128
public function newAction(Request $request)
125129
{
126130
$post = new Post();
127-
$form = $this->createForm(PostType::class, $post);
128-
$form->add('submit', SubmitType::class, array(
131+
$form = $this->createForm(new PostType(), $post);
132+
$form->add('submit', 'submit', array(
129133
'label' => 'Create',
130134
'attr' => array('class' => 'btn btn-default pull-right')
131135
));
@@ -209,3 +213,21 @@ Second, we recommend using ``$form->isSubmitted()`` in the ``if`` statement
209213
for clarity. This isn't technically needed, since ``isValid()`` first calls
210214
``isSubmitted()``. But without this, the flow doesn't read well as it *looks*
211215
like the form is *always* processed (even on the GET request).
216+
217+
Custom Form Field Types
218+
-----------------------
219+
220+
.. best-practice::
221+
222+
Add the ``app_`` prefix to your custom form field types to avoid collisions.
223+
224+
Custom form field types inherit from the ``AbstractType`` class, which defines the
225+
``getName()`` method to configure the name of that form type. These names must
226+
be unique in the application.
227+
228+
If a custom form type uses the same name as any of the Symfony's built-in form
229+
types, it will override it. The same happens when the custom form type matches
230+
any of the types defined by the third-party bundles installed in your application.
231+
232+
Add the ``app_`` prefix to your custom form field types to avoid name collisions
233+
that can lead to hard to debug errors.

Diff for: best_practices/i18n.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ Of all the available translation formats, only XLIFF and gettext have broad
3232
support in the tools used by professional translators. And since it's based
3333
on XML, you can validate XLIFF file contents as you write them.
3434

35-
Symfony supports notes in XLIFF files, making them more user-friendly for
36-
translators. At the end, good translations are all about context, and these
37-
XLIFF notes allow you to define that context.
35+
Symfony 2.6 added support for notes inside XLIFF files, making them more
36+
user-friendly for translators. At the end, good translations are all about
37+
context, and these XLIFF notes allow you to define that context.
3838

3939
.. tip::
4040

Diff for: best_practices/introduction.rst

+4
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,12 @@ installer and then execute this command to download the demo application:
7676

7777
.. code-block:: bash
7878
79+
# Linux and Mac OS X
7980
$ symfony demo
8081
82+
# Windows
83+
c:\> php symfony demo
84+
8185
**The demo application is a simple blog engine**, because that will allow us to
8286
focus on the Symfony concepts and features without getting buried in difficult
8387
implementation details. Instead of developing the application step by step in

0 commit comments

Comments
 (0)