2017 © Pedro Peláez
 

yii2-extension yii2-partial-content

Yii2 partial content filter.

image

kolyunya/yii2-partial-content

Yii2 partial content filter.

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Yii2 partial content filter

Description

A Yii2 filter which empowers a controller with a functionality of a partial HTTP response., (*1)

The widget is composer-enabled. You can aquire the latest available version from the packagist repository., (*2)

Usage example

The controller currently has four options to set the content to be sent to the client. Those options are contentData, contentResource, contentStream and the contentFile. The use of those properties is pretty straightforward. One of those properties will be used by the filter to send data to the client completly or partially depending on it's request. The filter should be added to the controller just like any other Yii2 action filter. You may also specify actions which should be processed by the filter., (*3)

The controller may also set the contentType property of the filter which will be used by the filter as a value of the Content-Type header. The default value is application/octet-stream., (*4)

The controller may also set the contentName property of the filter which will be used as a filename value of the Content-Disposition header. If the controller does not set this property this header will not be sent., (*5)

public function behaviors()
{

    return
    [

        // Add a partial content filter
        'partial-content' =>
        [

            // Specify filter class name
            'class' => 'kolyunya\yii2\filters\PartialContent',

            // Specify which actions it will be applied to
            'only' =>
            [
                'get'
            ]

        ]

    ];

}

public function actionGet()
{

    // Get a reference to the filter
    $behavior = $this->getBehavior('partial-content');

    // Now you have four options to set the data

    // [0] - Either set the data itself
    $behavior->contentData = $this->data;

    // [1] - Or specify the data resource
    $behavior->contentResource = $this->resource;

    // [2] - Or specify the data stream
    $behavior->contentStream = $this->stream;

    // [3] - Or specify the file name
    $behavior->contentFile = $this->file;

    // Optionally set the content type
    $behavior->contentType = 'audio/mpeg';

    // Optionally set the content name
    $behavior->contentName = 'My new song';

    // The filter will do the rest itself

}

The Versions

14/11 2014

dev-master

9999999-dev https://github.com/Kolyunya/yii2-partial-content

Yii2 partial content filter.

  Sources   Download

GNU GPL v3.0

extension filter yii2 http partial-content