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
Post a Comment