Git Product home page Git Product logo

Comments (6)

hhxsv5 avatar hhxsv5 commented on May 4, 2024

请提供可重现的代码示例。

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 4, 2024

swoole http server模式下 不能使用header()函数,需使用Laravel Response对象设置header。

from laravel-s.

never615 avatar never615 commented on May 4, 2024

楼主解决了吗?
父laravel-admin原库的导出代码:
这个会用到ob_end_clean函数,也没法用.有什么解决办法吗

    public function export()
    {
        $filename = $this->getTable().'.csv';

        $headers = [
            'Content-Encoding'    => 'UTF-8',
            'Content-Type'        => 'text/csv;charset=UTF-8',
            'Content-Disposition' => "attachment; filename=\"$filename\"",
        ];

        response()->stream(function () {
            $handle = fopen('php://output', 'w');

            $titles = [];

            $this->chunk(function ($records) use ($handle, &$titles) {
                if (empty($titles)) {
                    $titles = $this->getHeaderRowFromRecords($records);

                    // Add CSV headers
                    fputcsv($handle, $titles);
                }

                foreach ($records as $record) {
                    if ($record) {
                        fputcsv($handle, $this->getFormattedRecord($record));
                    }
                }
            });

            // Close the output stream
            fclose($handle);
        }, 200, $headers)->send();

        exit;
    }

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 4, 2024

源代码 Export
Swoole下不能用 exit,目前来看,你可以自己写个类,继承自CsvExporter,覆盖父类的export方法,这个方法中使用LaravelStreamDownload输出csv的内容,然后返回这个$response对象,交给上层Controller响应。

from laravel-s.

hhxsv5 avatar hhxsv5 commented on May 4, 2024

你得升级下LaravelS v3.5.4,刚刚才支持StreamedResponse

from laravel-s.

never615 avatar never615 commented on May 4, 2024

使用StreamedResponse,laravel-admin可以导出,同时需要修改laravel-admin基础源码:z-song/laravel-admin#3527

from laravel-s.

Related Issues (20)

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.