I am upgrading an old site in a much leaner and meaner code base, and im trying to migrate the old content in to the new site. I am trying to save to CSV (automatic download for now but would rather save straight to disk). From there I am going to use the CSV handler plugin (Thanks @texnixe) to bring the content into the new site.
I based this on another forum post:
c::set('routes', [
[
'pattern' => 'api/csv',
'action' => function() {
header::download(['mime'=>'application/csv', 'name' => 'blogpages.csv']);
$blogpages = site()->index()->find('blog')->children()->visible();
$blogpagefields = array();
foreach ($blogpages as $bpf) {
$blogpagefields[] = array(
'Title' => $bpf->title(),
'Date' => $bpf->date(),
'Author' => $bpf->author(),
'Featurehome' => $bpf->featurehome(),
'Featured' => $bpf->featured(),
'Text' => $bpf->text(),
'Categories' => $bpf->categories(),
'Tags' => $bpf->tags(),
'TitleTag' => $bpf->title-tag(),
'Description' => $bpf->description(),
'Keywords' => $bpf->keywords(),
'Modified' => $bpf->modified(),
'Schedule' => $bpf->schedule(),
);
}
$f = fopen('php://output', 'w');
foreach($blogpagefields as $blogpagelist) {
fputcsv($f, $blogpagelist, ';');
}
fpassthru($f);
return false;
}
]
]);
However, when I go to domain.test/api/csv
I get an error saying the page cannot be found (server page, not a woops or some other Kirby error - the server itself is saying it cant be reached). The rest of the site itself works. What have done wrong?