Skip to content

Commit 72c5839

Browse files
committed
Include PHP templating code examples
1 parent 979336b commit 72c5839

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

cookbook/controller/upload_file.rst

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,27 @@ Now, update the template that renders the form to display the new ``brochure``
8686
field (the exact template code to add depends on the method used by your application
8787
to :doc:`customize form rendering </cookbook/form/form_customization>`):
8888

89-
.. code-block:: html+twig
89+
.. configuration-block::
9090

91-
{# app/Resources/views/product/new.html.twig #}
92-
<h1>Adding a new product</h1>
91+
.. code-block:: html+twig
9392

94-
{{ form_start() }}
95-
{# ... #}
93+
{# app/Resources/views/product/new.html.twig #}
94+
<h1>Adding a new product</h1>
9695

97-
{{ form_row(form.brochure) }}
98-
{{ form_end() }}
96+
{{ form_start(form) }}
97+
{# ... #}
98+
99+
{{ form_row(form.brochure) }}
100+
{{ form_end(form) }}
101+
102+
.. code-block:: html+php
103+
104+
<!-- app/Resources/views/product/new.html.twig -->
105+
<h1>Adding a new product</h1>
106+
107+
<?php echo $view['form']->start($form) ?>
108+
<?php echo $view['form']->row($form['brochure']) ?>
109+
<?php echo $view['form']->end($form) ?>
99110

100111
Finally, you need to update the code of the controller that handles the form::
101112

@@ -169,10 +180,18 @@ There are some important things to consider in the code of the above controller:
169180
path as an application configuration option is considered a good practice that
170181
simplifies the code: ``$this->container->getParameter('brochures_dir')``.
171182

172-
You can now use the following code to link to the PDF brochure of an product:
183+
You can use the following code to link to the PDF brochure of an product:
184+
185+
.. configuration-block::
186+
187+
.. code-block:: html+twig
188+
189+
<a href="{{ asset('uploads/brochures/' ~ product.brochure) }}">View brochure (PDF)</a>
173190

174-
.. code-block:: html+twig
191+
.. code-block:: html+php
175192

176-
<a href="{{ asset('uploads/brochures/' ~ product.brochure) }}">View brochure (PDF)</a>
193+
<a href="<?php echo $view['assets']->getUrl('uploads/brochures/'.$product->getBrochure()) ?>">
194+
View brochure (PDF)
195+
</a>
177196

178197
.. _`VichUploaderBundle`: https://github.com/dustin10/VichUploaderBundle

0 commit comments

Comments
 (0)