Skip to content

Removed more PHP template examples #10020

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
48 changes: 13 additions & 35 deletions controller.rst
Original file line number Diff line number Diff line change
Expand Up @@ -417,47 +417,25 @@ you'll use this key to retrieve the message.
In the template of the next page (or even better, in your base layout template),
read any flash messages from the session:

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

.. code-block:: html+twig
{# app/Resources/views/base.html.twig #}

{# app/Resources/views/base.html.twig #}
{# you can read and display just one flash message type... #}
{% for flash_message in app.session.flashBag.get('notice') %}
<div class="flash-notice">
{{ flash_message }}
</div>
{% endfor %}

{# you can read and display just one flash message type... #}
{% for flash_message in app.session.flashBag.get('notice') %}
<div class="flash-notice">
{# ...or you can read and display every flash message available #}
{% for type, flash_messages in app.session.flashBag.all %}
{% for flash_message in flash_messages %}
<div class="flash-{{ type }}">
{{ flash_message }}
</div>
{% endfor %}

{# ...or you can read and display every flash message available #}
{% for type, flash_messages in app.session.flashBag.all %}
{% for flash_message in flash_messages %}
<div class="flash-{{ type }}">
{{ flash_message }}
</div>
{% endfor %}
{% endfor %}

.. code-block:: html+php

<!-- app/Resources/views/base.html.php -->

// you can read and display just one flash message type...
<?php foreach ($view['session']->getFlashBag()->get('notice') as $message): ?>
<div class="flash-notice">
<?php echo $message ?>
</div>
<?php endforeach ?>

// ...or you can read and display every flash message available
<?php foreach ($view['session']->getFlashBag()->all() as $type => $flash_messages): ?>
<?php foreach ($flash_messages as $flash_message): ?>
<div class="flash-<?php echo $type ?>">
<?php echo $message ?>
</div>
<?php endforeach ?>
<?php endforeach ?>
{% endfor %}

.. note::

Expand Down
38 changes: 10 additions & 28 deletions forms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,12 @@ done by passing a special form "view" object to your template (notice the
``$form->createView()`` in the controller above) and using a set of form
helper functions:

.. configuration-block::

.. code-block:: html+twig

{# app/Resources/views/default/new.html.twig #}
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}

.. code-block:: html+php
.. code-block:: html+twig

<!-- app/Resources/views/default/new.html.php -->
<?php echo $view['form']->start($form) ?>
<?php echo $view['form']->widget($form) ?>
<?php echo $view['form']->end($form) ?>
{# app/Resources/views/default/new.html.twig #}
{{ form_start(form) }}
{{ form_widget(form) }}
{{ form_end(form) }}

.. image:: /_images/form/simple-form.png
:align: center
Expand Down Expand Up @@ -432,21 +423,12 @@ Validation is a very powerful feature of Symfony and has its own
but are being prevented by your browser from, for example, submitting
blank fields.

.. configuration-block::

.. code-block:: html+twig

{# app/Resources/views/default/new.html.twig #}
{{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }}
{{ form_widget(form) }}
{{ form_end(form) }}

.. code-block:: html+php
.. code-block:: html+twig

<!-- app/Resources/views/default/new.html.php -->
<?php echo $view['form']->start($form, array('attr' => array('novalidate' => 'novalidate') ?>
<?php echo $view['form']->widget($form) ?>
<?php echo $view['form']->end($form) ?>
{# app/Resources/views/default/new.html.twig #}
{{ form_start(form, {'attr': {'novalidate': 'novalidate'}}) }}
{{ form_widget(form) }}
{{ form_end(form) }}

.. index::
single: Forms; Built-in field types
Expand Down
32 changes: 8 additions & 24 deletions security.rst
Original file line number Diff line number Diff line change
Expand Up @@ -879,19 +879,11 @@ Access Control in Templates
If you want to check if the current user has a role inside a template, use
the built-in ``is_granted()`` helper function:

.. configuration-block::

.. code-block:: html+twig
.. code-block:: html+twig

{% if is_granted('ROLE_ADMIN') %}
<a href="...">Delete</a>
{% endif %}

.. code-block:: html+php

<?php if ($view['security']->isGranted('ROLE_ADMIN')): ?>
<a href="...">Delete</a>
<?php endif ?>
{% if is_granted('ROLE_ADMIN') %}
<a href="...">Delete</a>
{% endif %}

.. note::

Expand Down Expand Up @@ -1070,19 +1062,11 @@ Retrieving the User in a Template
In a Twig Template this object can be accessed via the :ref:`app.user <reference-twig-global-app>`
key:

.. configuration-block::

.. code-block:: html+twig

{% if is_granted('IS_AUTHENTICATED_FULLY') %}
<p>Username: {{ app.user.username }}</p>
{% endif %}

.. code-block:: html+php
.. code-block:: html+twig

<?php if ($view['security']->isGranted('IS_AUTHENTICATED_FULLY')): ?>
<p>Username: <?php echo $app->getUser()->getUsername() ?></p>
<?php endif; ?>
{% if is_granted('IS_AUTHENTICATED_FULLY') %}
<p>Username: {{ app.user.username }}</p>
{% endif %}

.. _security-logging-out:

Expand Down
Loading