tenolo/referer-bundle

Provides simple functions to use and set referer.

Installs: 132

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 2

Forks: 0

Open Issues: 0

Type:symfony-bundle

1.0.0 2019-07-19 10:03 UTC

This package is auto-updated.

Last update: 2024-03-19 20:19:11 UTC


README

tenolo

PHP Version Latest Stable Version Latest Unstable Version Total Downloads Total Downloads License

Referer Bundle

Helpful in Twig Templates. Allows you to set a static referer that can be set across multiple page views using the session to get back to a specific page using a Twig function. This can be used to generate a "Back" button.

Install instructions

First you need to add tenolo/referer-bundle to composer.json:

Let Composer do it for you.

$ composer require tenolo/referer-bundle

or do it manually

{
   "require": {
        "tenolo/referer-bundle": "~1.0"
    }
}

Please note that dev-master latest development version. Of course you can also use an explicit version number, e.g., 1.0.*.

Usage

To go back to the last page

{# check for a static referer #}
{% if referer_has() %}
    <a href="{{ referer_uri() }}">Go back</a>
{% endif %}

If no static referer was set, the referer from the header of the request is used.

To set a static referer.

<a href="{{ path('route_name_of_next_page', { param: value })|referer_query }}">Next Page</a>

The link is manipulated so that the library remembers the current page. If the Twig function "referer_uri" is called on one of the later pages, a link is generated that links back to the current page.