Hi all,
i have a problem with the demo database tutorial:
https://getkirby.com/docs/guide/virtual-pages/content-from-database
Adding a new page does not work also change the page slug does not work.
app.js:1 {status: “error”, route: “pages/([a-zA-Z0-9.-_%= +@()]+)”, exception: “Kirby\Exception\NotFoundException”, message: “Die Seite “items/asdasdasd” konnte nicht gefunden werden”, key: “error.page.notFound”, …}
Edit the content works.
class ItemsPage extends Kirby\Cms\Page
{
public function children()
{
$items= [];
foreach (Db::select('items') as $item) {
$items[] = [
'slug' => $item->slug(),
'num' => 0,
'template' => 'item',
'model' => 'item',
'content' => [
'name' => $item->name(),
'zip' => $item->zip(),
]
];
}
return Pages::factory($items, $this);
}
}
class ItemPage extends Kirby\Cms\Page
{
public function writeContent(array $data, string $languageCode = null): bool
{
unset($data['title']);
if ($item = Db::first('items', '*', ['slug' => $this->slug()])) {
return Db::update('items', $data, ['slug' => $this->slug()]);
} else {
$data['slug'] = $this->slug();
return Db::insert('items', $data);
}
}
public function delete(bool $force = false): bool
{
return Db::delete('items', ['slug' => $this->slug()]);
}
public function title(): Kirby\Cms\Field
{
return $this->text()->excerpt(100)->or('New item');
}
}
any ideas?