zerkalica/millwright-filter-bundle

There is no license information available for the latest version (dev-master) of this package.

Millwright filter bundle: glue together KnpPaginatorBundle and LexikFormFilterBundle

dev-master 2012-10-19 21:21 UTC

This package is not auto-updated.

Last update: 2024-11-09 15:00:35 UTC


README

Glue together KnpPaginatorBundle and LexikFormFilterBundle.

  • Inject service @millwright_filter.paginator

  • Use PaginatorInterface $paginator;

  • Use $this->paginator->paginate($builder, 'users', $form);

  • builder - QueryBuilder or something to paginate

  • 'user' - paginator parameters and query builder namespce

  • form - filter form, see LexikFormFilterBundle

Services

millwright_filter.registry used for storing query parameters (see OptionsRegistryInterface)

Twig functions

Used for saving paginator and filter state in get parameters.

options_registry(exclude_namespace, overrides) - returns array, used for sharing query parameters between filter form and paginator:

{% beginmacro form(form, attributes) %}
    <form {{ form_enctype(form) }} {{ _self.attributes(attributes) }} novalidate>
    {{ form_widget(form) }}
    {#
        options_registry(form.vars.name) - build http query with all stored parameters, except this form
    #}
    {% for key, value in options_registry(form.vars.name) %}
        <input name="{{ key }}" value="{{ value }}" type="hidden" />
    {% endfor %}
    </form>
{% endmacro form %}

options_query(overrides, exlude_namespace) - returns string, builds http query, used for links (paginator, filters state):

<a href="?{{ options_query({current: next}) }}">Prev</a>
<a href="?{{ options_query({current: prev}) }}">Next</a>

In controller:

    /** @var $options \Millwright\Util\Request\OptionRegistryInterface */
    $options = $this->get('millwright_filter.registry');
    $options->addOption('current', $currentDate->format(DateUtil::SQL_DATE));

    return array('next' => 'next week', 'prev' => 'prev week', 'paginator' => $paginator, 'filter' => $form);