Coder Social home page Coder Social logo

kolyunya / yii2-partial-content Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 0.0 292 KB

A Yii2 filter which empowers a controller with a functionality of a partial HTTP response. The widget is composer-enabled. You can aquire the latest available version from the packagist repository.

License: GNU General Public License v3.0

PHP 100.00%

yii2-partial-content's Introduction

#Yii2 partial content filter

##Description

A Yii2 filter which empowers a controller with a functionality of a partial HTTP response.

The widget is composer-enabled. You can aquire the latest available version from the packagist repository.

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

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.

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.

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

}

yii2-partial-content's People

Contributors

kolyunya avatar

Stargazers

 avatar

Watchers

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