FriendsOfCake/cakephp-csvview

Need extra line of code in one of the examples

paulmorriss opened this issue · 5 comments

I'm using Cake PHP 2.4.5. When I used the code as you have in the snippet above the line

// Access /posts/export.csv to get the data as csv

I found that I also needed the line

$this->viewClass = 'CsvView.Csv';

otherwise I got the error

View file "\app\View\csv\export.ctp" is missing.

Can you paste the whole snippet? I dont know which one you are referring to.

// In your routes.php file:
Router::parseExtensions('csv');

// In your controller:
public $components = array(
    'RequestHandler' => array(
        'viewClassMap' => array('csv' => 'CsvView.Csv)
    )
);

public function export() {
    $posts = $this->Post->find('all');
    $_serialize = 'posts';
    $_header = array('Post ID', 'Title', 'Created');
    $_extract = array('Post.id', 'Post.title', 'Post.created');

    $this->set(compact('posts', '_serialize', '_header', '_extract'));
}

We just updated the docks so it would work properly. The docs you just
pasted are now correct. Previously they were omitting the viewClassMap.

On Fri, Mar 7, 2014 at 1:40 PM, Paul Morriss notifications@github.comwrote:

// In your routes.php file:Router::parseExtensions('csv');
// In your controller:public $components = array(
'RequestHandler' => array(
'viewClassMap' => array('csv' => 'CsvView.Csv) ));
public function export() { $posts = $this->Post->find('all'); $_serialize = 'posts'; $_header = array('Post ID', 'Title', 'Created'); $_extract = array('Post.id', 'Post.title', 'Post.created');
$this->set(compact('posts', '_serialize', '_header', '_extract'));}

Reply to this email directly or view it on GitHubhttps://github.com//issues/25#issuecomment-37053871
.

Thanks for sorting that out. However there's a missing close quote after CsvView.Csv.

Fixed with #27