src/Controller/SearchTrait.php
public function exportSearch(string $id, string $filename)
    {
        $filename = '' === trim($filename) ? $this->name : $filename;
        $export = new Export($id, $filename, $this->Auth->user());

        if ($this->request->is('ajax') && $this->request->accepts('application/json')) {
            $page = (int)Hash::get($this->request->getQueryParams(), 'page', 1);
            $limit = (int)Hash::get($this->request->getQueryParams(), 'limit', Configure::read('Search.export.limit'));

            $export->execute($page, $limit);

            $result = [
                'success' => true,
                'data' => ['path' => $export->getUrl()],
                '_serialize' => ['success', 'data']
            ];

            $this->set($result);

            return;
        }

        $this->set('count', $export->count());
        $this->set('filename', $filename);
        $this->render('Search.Search/export');
    }
public function exportSearch(string $id, string $filename)
    {
        $filename = '' === trim($filename) ? $this->name : $filename;
        $export = new Export($id, $filename, $this->Auth->user());

        if ($this->request->is('ajax') && $this->request->accepts('application/json')) {
            $page = (int)Hash::get($this->request->getQueryParams(), 'page', 1);
            $limit = (int)Hash::get($this->request->getQueryParams(), 'limit', Configure::read('Search.export.limit'));

            $export->execute($page, $limit);

            $result = [
                'success' => true,
                'data' => ['path' => $export->getUrl()],
                '_serialize' => ['success', 'data']
            ];

            $this->set($result);

            return;
        }

        $this->set('count', $export->count());
        $this->set('filename', $filename);
        $this->render('Search.Search/export');
    }
public function exportSearch ( string $ id , string $ filename ) { $ filename = '' === trim ( $ filename ) ? $ this -> name : $ filename ; $ export = new Export ( $ id , $ filename , $ this -> Auth -> user ( ) ) ; if ( $ this -> request -> is ( 'ajax' ) && $ this -> request -> accepts ( 'application/json' ) ) { $ page = ( int ) Hash :: get ( $ this -> request -> getQueryParams ( ) , 'page' , 1 ) ; $ limit = ( int ) Hash :: get ( $ this -> request -> getQueryParams ( ) , 'limit' , Configure :: read ( 'Search.export.limit' ) ) ; $ export -> execute ( $ page , $ limit ) ; $ result = [ 'success' => true , 'data' => [ 'path' => $ export -> getUrl ( ) ] , '_serialize' => [ 'success' , 'data' ] ] ; $ this -> set ( $ result ) ; return ; } $ this -> set ( 'count' , $ export -> count ( ) ) ; $ this -> set ( 'filename' , $ filename ) ; $ this -> render ( 'Search.Search/export' ) ; }
Export Search results

Method responsible for exporting search results
into a CSV file and forcing file download.

@param string $id Pre-saved search id
@param string $filename Export filename
@return \Cake\Http\Response|void
Export Search results