2017 © Pedro Peláez
 

symfony-bundle pjax-bundle

Symfony bundle that provide a lightweight yet powerfull integration with pjax jQuery plugin.

image

gremo/pjax-bundle

Symfony bundle that provide a lightweight yet powerfull integration with pjax jQuery plugin.

  • Saturday, September 16, 2017
  • by gremo
  • Repository
  • 1 Watchers
  • 3 Stars
  • 361 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 3 Versions
  • 3 % Grown

The README.md

GremoPjaxBundle

Latest stable Downloads total GitHub issues, (*1)

Symfony bundle that provide a lightweight yet powerfull integration with pjax jQuery plugin., (*2)

New contributors are welcome!, (*3)

Installation

Add the bundle in your composer.json file:, (*4)

{
    "require": {
        "gremo/pjax-bundle": "~1.0"
    }
}

Then enable the bundle in the kernel:, (*5)

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Gremo\PjaxBundle\GremoPjaxBundle(),
        // ...
    );
}

Configuration

Integration is disabled by default, see "Usage" to find out which method you need to enable., (*6)

Short configuration:, (*7)

# GremoPjaxBundle Configuration
gremo_pjax:
    annotations:          false # should annotations be enabled?
    controller_injection: false # should controller injection be enabled?

Full configuration and defaults:, (*8)

# GremoPjaxBundle Configuration
gremo_pjax:
    # Annotations configuration
    annotations:
        enabled: false # should annotations be enabled?
        # Annotation defaults (see "Annotations")
        defaults:
            version: ~
            filter:  true

    # Controller injection configuration
    controller_injection:
        enabled: false # should controller injection be enabled?
        # How controller parameters should be named?
        parameters:
            X-PJAX: _isPjax
            X-PJAX-Container: _pjaxContainer

Usage

This bundle provides two different types of integration: annotations and controller injection., (*9)

Annotations

This is the most unobtrusive way and it's fully automatic:, (*10)

  • You don't need custom template logic or controller logic
  • Response HTML is automatically filtered (if filter option is true) and a <title> tag is injected in the pjax container fragment
  • Response time will slightly increase due to the filtering logic, but you still save bandwidth

Note: everything that is not a successfull response or text/html is simply ignored., (*11)

Available options: - version (string, default null): sets the pjax version (see Layout Reloading) - filter (bool, default true): whatever respose should contain only the pjax container or the full HTML, (*12)

Note: annotations defined on a controller action inherit from class annotation and replace defaults from configuration., (*13)

The @Pjax annotation on a controller class defines all action routes as pjax-aware:, (*14)

<?php

use Gremo\PjaxBundle\Annotation\Pjax;

/**
 * @Pjax(version="1.2")
 */
class DefaultController extends Controller
{
    // ...
}

Instead, on a controller action, the annotation defines the route as pjax-aware:, (*15)

<?php

use Gremo\PjaxBundle\Annotation\Pjax;

class DefaultController extends Controller
{
    /**
     * @Pjax(filter=false)
     */
    public function indexAction(Request $request)
    {
        // ...
    }
}

Controller injection

This is the most obtrusive way but potentially the most powerful one:, (*16)

  • You need to define the pjax action parameters (names are configurable)
  • You need to define a custom template/controller logic for returing the full HTML or just the pjax container
  • Extra logic allows to save queries and reduce the response time
<?php

class DefaultController extends Controller
{
    /**
     * @Route("/", name="homepage")
     */
    public function indexAction(Request $request, $_isPjax, $_pjaxContainer)
    {
        if ($_isPjax) {
            // Return just the pjax container HTML if pjax is enabled
            // ...
        }

        // Return the full layout
        // ...
    }
}

The Versions

16/09 2017

dev-master

9999999-dev

Symfony bundle that provide a lightweight yet powerfull integration with pjax jQuery plugin.

  Sources   Download

MIT

The Requires

 

jquery ajax pjax pushstate

30/04 2016

v1.0.1

1.0.1.0

Symfony bundle that provide a lightweight yet powerfull integration with pjax jQuery plugin.

  Sources   Download

MIT

The Requires

 

jquery ajax pjax pushstate

16/03 2016

v1.0.0

1.0.0.0

Symfony 2 bundle that provide a lightweight yet powerfull integration with pjax jQuery plugin.

  Sources   Download

MIT

The Requires

 

jquery ajax pjax pushstate