@@ -86,16 +86,27 @@ Now, update the template that renders the form to display the new ``brochure``
86
86
field (the exact template code to add depends on the method used by your application
87
87
to :doc: `customize form rendering </cookbook/form/form_customization >`):
88
88
89
- .. code -block :: html+twig
89
+ .. configuration -block ::
90
90
91
- {# app/Resources/views/product/new.html.twig #}
92
- <h1>Adding a new product</h1>
91
+ .. code-block :: html+twig
93
92
94
- {{ form_start() } }
95
- {# ... #}
93
+ {# app/Resources/views/product/new.html.twig # }
94
+ <h1>Adding a new product</h1>
96
95
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) ?>
99
110
100
111
Finally, you need to update the code of the controller that handles the form::
101
112
@@ -169,10 +180,18 @@ There are some important things to consider in the code of the above controller:
169
180
path as an application configuration option is considered a good practice that
170
181
simplifies the code: ``$this->container->getParameter('brochures_dir') ``.
171
182
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>
173
190
174
- .. code-block :: html+twig
191
+ .. code-block :: html+php
175
192
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>
177
196
178
197
.. _`VichUploaderBundle` : https://github.com/dustin10/VichUploaderBundle
0 commit comments