Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit88c2163

Browse files
committed
Removed the code of the PHP templates
1 parent676fc4e commit88c2163

24 files changed

+373
-1057
lines changed

‎controller/upload_file.rst‎

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -83,27 +83,16 @@ Now, update the template that renders the form to display the new ``brochure``
8383
field (the exact template code to add depends on the method used by your application
8484
to:doc:`customize form rendering</form/form_customization>`):
8585

86-
..configuration-block::
87-
88-
..code-block::html+twig
89-
90-
{# app/Resources/views/product/new.html.twig #}
91-
<h1>Adding a new product</h1>
92-
93-
{{ form_start(form) }}
94-
{# ... #}
95-
96-
{{ form_row(form.brochure) }}
97-
{{ form_end(form) }}
86+
..code-block::html+twig
9887

99-
..code-block::html+php
88+
{# app/Resources/views/product/new.html.twig #}
89+
<h1>Adding a new product</h1>
10090

101-
<!-- app/Resources/views/product/new.html.php -->
102-
<h1>Adding a new product</h1>
91+
{{ form_start(form) }}
92+
{# ... #}
10393

104-
<?php echo $view['form']->start($form) ?>
105-
<?php echo $view['form']->row($form['brochure']) ?>
106-
<?php echo $view['form']->end($form) ?>
94+
{{ form_row(form.brochure) }}
95+
{{ form_end(form) }}
10796

10897
Finally, you need to update the code of the controller that handles the form::
10998

@@ -197,17 +186,9 @@ There are some important things to consider in the code of the above controller:
197186

198187
You can use the following code to link to the PDF brochure of a product:
199188

200-
..configuration-block::
201-
202-
..code-block::html+twig
203-
204-
<a href="{{ asset('uploads/brochures/' ~ product.brochure) }}">View brochure (PDF)</a>
205-
206-
..code-block::html+php
189+
..code-block::html+twig
207190

208-
<a href="<?php echo $view['assets']->getUrl('uploads/brochures/'.$product->getBrochure()) ?>">
209-
View brochure (PDF)
210-
</a>
191+
<a href="{{ asset('uploads/brochures/' ~ product.brochure) }}">View brochure (PDF)</a>
211192

212193
..tip::
213194

‎doctrine/registration_form.rst‎

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -363,34 +363,18 @@ the :ref:`user password encoding <security-encoding-user-password>` article.
363363
364364
Next, create the template:
365365

366-
..configuration-block::
367-
368-
..code-block::html+twig
369-
370-
{# app/Resources/views/registration/register.html.twig #}
371-
372-
{{ form_start(form) }}
373-
{{ form_row(form.username) }}
374-
{{ form_row(form.email) }}
375-
{{ form_row(form.plainPassword.first) }}
376-
{{ form_row(form.plainPassword.second) }}
377-
378-
<button type="submit">Register!</button>
379-
{{ form_end(form) }}
380-
381-
..code-block::html+php
382-
383-
<!-- app/Resources/views/registration/register.html.php -->
366+
..code-block::html+twig
384367

385-
<?php echo $view['form']->start($form) ?>
386-
<?php echo $view['form']->row($form['username']) ?>
387-
<?php echo $view['form']->row($form['email']) ?>
368+
{# app/Resources/views/registration/register.html.twig #}
388369

389-
<?php echo $view['form']->row($form['plainPassword']['first']) ?>
390-
<?php echo $view['form']->row($form['plainPassword']['second']) ?>
370+
{{ form_start(form) }}
371+
{{ form_row(form.username) }}
372+
{{ form_row(form.email) }}
373+
{{ form_row(form.plainPassword.first) }}
374+
{{ form_row(form.plainPassword.second) }}
391375

392-
<button type="submit">Register!</button>
393-
<?php echo $view['form']->end($form)?>
376+
<button type="submit">Register!</button>
377+
{{ form_end(form)}}
394378

395379
See:doc:`/form/form_customization` for more details.
396380

‎form/action_method.rst‎

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -115,22 +115,10 @@ options:
115115
Finally, you can override the action and method in the template by passing them
116116
to the ``form()`` or the ``form_start()`` helper functions:
117117

118-
..configuration-block::
119-
120-
..code-block::html+twig
121-
122-
{# app/Resources/views/default/new.html.twig #}
123-
{{ form_start(form, {'action': path('target_route'), 'method': 'GET'}) }}
118+
..code-block::html+twig
124119

125-
..code-block::html+php
126-
127-
<!-- app/Resources/views/default/new.html.php -->
128-
<?php echo $view['form']->start($form, array(
129-
// The path() method was introduced in Symfony 2.8. Prior to 2.8,
130-
// you had to use generate().
131-
'action' => $view['router']->path('target_route'),
132-
'method' => 'GET',
133-
)) ?>
120+
{# app/Resources/views/default/new.html.twig #}
121+
{{ form_start(form, {'action': path('target_route'), 'method': 'GET'}) }}
134122

135123
..note::
136124

‎form/create_custom_field_type.rst‎

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -123,45 +123,26 @@ But for the sake of this example, suppose that when your field is "expanded"
123123
always render it in a ``ul`` element. In your form theme template (see above
124124
link for details), create a ``shipping_widget`` block to handle this:
125125

126-
..configuration-block::
127-
128-
..code-block::html+twig
129-
130-
{# app/Resources/views/form/fields.html.twig #}
131-
{% block shipping_widget %}
132-
{% spaceless %}
133-
{% if expanded %}
134-
<ul {{ block('widget_container_attributes') }}>
135-
{% for child in form %}
136-
<li>
137-
{{ form_widget(child) }}
138-
{{ form_label(child) }}
139-
</li>
140-
{% endfor %}
141-
</ul>
142-
{% else %}
143-
{# just let the choice widget render the select tag #}
144-
{{ block('choice_widget') }}
145-
{% endif %}
146-
{% endspaceless %}
147-
{% endblock %}
148-
149-
..code-block::html+php
150-
151-
<!-- app/Resources/views/form/shipping_widget.html.php -->
152-
<?php if ($expanded) : ?>
153-
<ul <?php $view['form']->block($form, 'widget_container_attributes') ?>>
154-
<?php foreach ($form as $child) : ?>
155-
<li>
156-
<?php echo $view['form']->widget($child) ?>
157-
<?php echo $view['form']->label($child) ?>
158-
</li>
159-
<?php endforeach ?>
160-
</ul>
161-
<?php else : ?>
162-
<!-- just let the choice widget render the select tag -->
163-
<?php echo $view['form']->renderBlock('choice_widget') ?>
164-
<?php endif ?>
126+
..code-block::html+twig
127+
128+
{# app/Resources/views/form/fields.html.twig #}
129+
{% block shipping_widget %}
130+
{% spaceless %}
131+
{% if expanded %}
132+
<ul {{ block('widget_container_attributes') }}>
133+
{% for child in form %}
134+
<li>
135+
{{ form_widget(child) }}
136+
{{ form_label(child) }}
137+
</li>
138+
{% endfor %}
139+
</ul>
140+
{% else %}
141+
{# just let the choice widget render the select tag #}
142+
{{ block('choice_widget') }}
143+
{% endif %}
144+
{% endspaceless %}
145+
{% endblock %}
165146

166147
..tip::
167148

‎form/create_form_type_extension.rst‎

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -266,31 +266,21 @@ In your extension class, you have added a new variable (``image_url``), but
266266
you still need to take advantage of this new variable in your templates.
267267
Specifically, you need to override the ``file_widget`` block:
268268

269-
..configuration-block::
270-
271-
..code-block::html+twig
272-
273-
{# src/AppBundle/Resources/views/Form/fields.html.twig #}
274-
{% extends 'form_div_layout.html.twig' %}
275-
276-
{% block file_widget %}
277-
{% spaceless %}
269+
..code-block::html+twig
278270

279-
{{ block('form_widget') }}
280-
{% if image_url is not null %}
281-
<img src="{{ asset(image_url) }}"/>
282-
{% endif %}
271+
{# src/AppBundle/Resources/views/Form/fields.html.twig #}
272+
{% extends 'form_div_layout.html.twig' %}
283273

284-
{%endspaceless %}
285-
{%endblock %}
274+
{%block file_widget %}
275+
{%spaceless %}
286276

287-
..code-block::html+php
277+
{{ block('form_widget') }}
278+
{% if image_url is not null %}
279+
<img src="{{ asset(image_url) }}"/>
280+
{% endif %}
288281

289-
<!-- src/AppBundle/Resources/views/Form/file_widget.html.php -->
290-
<?php echo $view['form']->widget($form) ?>
291-
<?php if (null !== $image_url): ?>
292-
<img src="<?php echo $view['assets']->getUrl($image_url) ?>"/>
293-
<?php endif ?>
282+
{% endspaceless %}
283+
{% endblock %}
294284

295285
..note::
296286

‎form/dynamic_form_modification.rst‎

Lines changed: 34 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -585,77 +585,40 @@ your application. Assume that you have a sport meetup creation controller::
585585
The associated template uses some JavaScript to update the ``position`` form
586586
field according to the current selection in the ``sport`` field:
587587

588-
..configuration-block::
589-
590-
..code-block::html+twig
591-
592-
{# app/Resources/views/meetup/create.html.twig #}
593-
{{ form_start(form) }}
594-
{{ form_row(form.sport) }} {# <select id="meetup_sport" ... #}
595-
{{ form_row(form.position) }} {# <select id="meetup_position" ... #}
596-
{# ... #}
597-
{{ form_end(form) }}
598-
599-
<script>
600-
var $sport = $('#meetup_sport');
601-
// When sport gets selected ...
602-
$sport.change(function() {
603-
// ... retrieve the corresponding form.
604-
var $form = $(this).closest('form');
605-
// Simulate form data, but only include the selected sport value.
606-
var data = {};
607-
data[$sport.attr('name')] = $sport.val();
608-
// Submit data via AJAX to the form's action path.
609-
$.ajax({
610-
url : $form.attr('action'),
611-
type: $form.attr('method'),
612-
data : data,
613-
success: function(html) {
614-
// Replace current position field ...
615-
$('#meetup_position').replaceWith(
616-
// ... with the returned one from the AJAX response.
617-
$(html).find('#meetup_position')
618-
);
619-
// Position field now displays the appropriate positions.
620-
}
621-
});
622-
});
623-
</script>
624-
625-
..code-block::html+php
626-
627-
<!-- app/Resources/views/Meetup/create.html.php -->
628-
<?php echo $view['form']->start($form) ?>
629-
<?php echo $view['form']->row($form['sport']) ?> <!-- <select id="meetup_sport" ... -->
630-
<?php echo $view['form']->row($form['position']) ?> <!-- <select id="meetup_position" ... -->
631-
<!-- ... -->
632-
<?php echo $view['form']->end($form) ?>
633-
634-
<script>
635-
var $sport = $('#meetup_sport');
636-
// When sport gets selected ...
637-
$sport.change(function() {
638-
// ... retrieve the corresponding form.
639-
var $form = $(this).closest('form');
640-
// Simulate form data, but only include the selected sport value.
641-
var data = {};
642-
data[$sport.attr('name')] = $sport.val();
643-
// Submit data via AJAX to the form's action path.
644-
$.ajax({
645-
url : $form.attr('action'),
646-
type: $form.attr('method'),
647-
data : data,
648-
success: function(html) {
649-
// Replace current position field ...
650-
$('#meetup_position').replaceWith(
651-
// ... with the returned one from the AJAX response.
652-
$(html).find('#meetup_position')
653-
);
654-
// Position field now displays the appropriate positions.
655-
}
656-
});
657-
});
658-
</script>
588+
..code-block::html+twig
589+
590+
{# app/Resources/views/meetup/create.html.twig #}
591+
{{ form_start(form) }}
592+
{{ form_row(form.sport) }} {# <select id="meetup_sport" ... #}
593+
{{ form_row(form.position) }} {# <select id="meetup_position" ... #}
594+
{# ... #}
595+
{{ form_end(form) }}
596+
597+
<script>
598+
var $sport = $('#meetup_sport');
599+
// When sport gets selected ...
600+
$sport.change(function() {
601+
// ... retrieve the corresponding form.
602+
var $form = $(this).closest('form');
603+
// Simulate form data, but only include the selected sport value.
604+
var data = {};
605+
data[$sport.attr('name')] = $sport.val();
606+
// Submit data via AJAX to the form's action path.
607+
$.ajax({
608+
url : $form.attr('action'),
609+
type: $form.attr('method'),
610+
data : data,
611+
success: function(html) {
612+
// Replace current position field ...
613+
$('#meetup_position').replaceWith(
614+
// ... with the returned one from the AJAX response.
615+
$(html).find('#meetup_position')
616+
);
617+
// Position field now displays the appropriate positions.
618+
}
619+
});
620+
});
621+
</script>
659622

660623
The major benefit of submitting the whole form to just extract the updated
661624
``position`` field is that no additional server-side code is needed; all the

‎form/embedded.rst‎

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,29 +109,16 @@ the ``TaskType`` class.
109109

110110
Render the ``Category`` fields in the same way as the original ``Task`` fields:
111111

112-
..configuration-block::
112+
..code-block::html+twig
113113

114-
..code-block::html+twig
114+
{# ... #}
115115

116-
{# ... #}
116+
<h3>Category</h3>
117+
<div class="category">
118+
{{ form_row(form.category.name) }}
119+
</div>
117120

118-
<h3>Category</h3>
119-
<div class="category">
120-
{{ form_row(form.category.name) }}
121-
</div>
122-
123-
{# ... #}
124-
125-
..code-block::html+php
126-
127-
<!-- ... -->
128-
129-
<h3>Category</h3>
130-
<div class="category">
131-
<?php echo $view['form']->row($form['category']['name']) ?>
132-
</div>
133-
134-
<!-- ... -->
121+
{# ... #}
135122

136123
When the user submits the form, the submitted data for the ``Category`` fields
137124
are used to construct an instance of ``Category``, which is then set on the

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp