Hi everyone,
I try to connect kirby3 to a database. The database contains event infos and i want to show an overview of all events and also create child pages for every event.
I worked with the Cookbook but run into some issues.
My template model “models/events.php” looks like this:
<?php
class EventsPage extends Kirby\Cms\Page
{
public function children()
{
$events = [];
foreach (Db::select('veranstaltung') as $event) {
$events[] = [
'slug' => $event->slug(), //ID + Titel unique
'num' => 0,
'template' => 'events',
'model' => 'events',
'content' => [
'id' => $event->event_id(), //unique Event ID
'ip_titel' => $event->event_title(), //Event Title
'ip_utitel' => $event->event_subline(), // Event Subline
'tx_web_short' => $event->event_teaser(), // Event Teaser
'sl_kat' => $event->event_category(), // Event Category
'dt_datum' => $event->event_date(), // Event Date
'tx_prog' => $event->event_description(), // Event Descripton
'hm_einlass' => $event->event_opening(), // Event Doors open
'hm_beginn' => $event->event_start(), // Event beginns
'cr_preis_vvk' => $event->event_presale(), // pre sale price
'cr_preis_ak' => $event->event_boxoffice(), // Box Offcie price
]
];
}
return Pages::factory($events, $this);
}
}
?>
and my template /templates/event.php looks like that:
<?php $events = Db::select('veranstaltung'); ?>
<?php snippet('header') ?>
<?php snippet('menu') ?>
<div class="container">
<div class="row">
<?php foreach ($page->children() as $event): ?>
<div class="col s12 m8 offset-m2">
<div class="card">
<div class="card-image">
<span class="card-title"><?= $event->event_title() ?></span>
</div>
<div class="card-content">
<p><?= $event->event_description() ?></p>
</div>
<div class="card-action">
<a href="<?= $event->url() ?>">Mehr...</a>
</div>
</div>
</div>
<?php endforeach ?>
</div>
</div>
<?php snippet('footer') ?>
The result looks like this: This is just one card of all created events, but the look alle the same. except the url.
<div class="col s12 m8 offset-m2">
<div class="card">
<div class="card-image">
<span class="card-title"></span>
</div>
<div class="card-content">
<p></p>
</div>
<div class="card-action">
<a href="https://kirby3-mysql:8890/events/100312_margie-kinsky">Mehr...</a>
</div>
</div>
</div>
Only the slug() content was sent out of the db. I
just don’t think I see it now. That’s why I’m very grateful for a “second pair of eyes”.