Giter Club home page Giter Club logo

gremopjaxbundle's Introduction

PjaxBundle

Latest stable Downloads total GitHub issues

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

New contributors are welcome!

Installation

Add the bundle in your composer.json file:

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

Then enable the bundle in the kernel:

<?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.

Short configuration:

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

Full configuration and defaults:

# 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.

Annotations

This is the most unobtrusive way and it's fully automatic:

  • You don't need custom template logic or controller logic
  • Response HTML is automatically filtered (il 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.

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

Note: annotations defined on a controller action inherit from class annotation and replace defaults from configuration.

The @Pjax annotation on a controller class defines all action routes as pjax-aware:

<?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:

<?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:

  • 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
        // ...
    }
}

gremopjaxbundle's People

Contributors

gremo avatar

Watchers

James Cloos avatar Paulius Aleksiūnas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.