FriendsOfCake / cakephp-csvview

CakePHP: A view class for generating CSV
MIT License
176 stars 64 forks source link

csvView save only html code #105

Closed dgtlslave closed 4 years ago

dgtlslave commented 5 years ago

Hi, I have little problem. CsvView save in csv file only html code, something like that:<!DOCTYPE html> ... and whole page... Help pls. What did I miss? Thks

dgtlslave commented 5 years ago
public function export() {
        $this->response->download('export.csv');
        $data = [
            ['a', 'b', 'c'],
            [1, 2, 3],
            ['you', 'and', 'me'],
        ];
        $_serialize = 'data';
        $this->set(compact('data', '_serialize'));
        $this->viewBuilder()->className('CsvView.Csv');
        return;
}
dgtlslave commented 5 years ago

Router::extensions(['csv']);

dgtlslave commented 5 years ago

And when I try to start function with uncommeted '_ext' => 'csv' I have an error: Error: Create ProjectsController::export.csv() in file: src/Controller/ProjectsController.php. Above is my button.

`<?= $this->Html->link('save', [
        'controller' => 'Projects', 
        'action' => 'export',
        // '_ext' => 'csv'
        ],

        ['class' => 'btn btn-success']) 
      ?>`
dgtlslave commented 5 years ago

@dereuromark can you help me? Sorry for the taking time )

dereuromark commented 5 years ago

If the docs are unclear here, you can also compare yours with sandbox code, what you might have missed.

dgtlslave commented 5 years ago

Thanks. The problem is plugin insert Router::extensions(['csv']); like last row in my routes.php
When I picked up row with csv routes plugin start to work correct

dereuromark commented 5 years ago

Anything to improve the docs of this plugin here? Otherwise you can close this ticket then.