php - have Restler method return a Content-Disposition header -



php - have Restler method return a Content-Disposition header -

in 1 of methods possible specify specific content-type , content-disposition? after getting info i'm doing this:

class="lang-js prettyprint-override">return scope::get('csvformat')->encode($data);

and info returned in csv format. want set content type text/csv , set content-disposition allows file download, instead of showing content.

here working example!

in excel.php

<?php class excel { /** * download csv info can rendered excel * * @return array * @format csvformat * @header content-disposition: attachment; filename="excel.csv" */ public function download() { //csv compatible array $data = [['name' => 'john doe', 'age' => '23'], ['name' => 'mika', 'age' => '45']]; homecoming $data; } }

your index.php

<?php require '../vendor/autoload.php'; utilize luracast\restler\restler; $r = new restler(); $r->addapiclass('excel'); $r->setoverridingformats('csvformat'); $r->handle();

try http://localhost/excel/download

php restler

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -