Writing content into database via panel

Hi everyone,

based on this guide Content from a database | Kirby CMS i try to store content in a database. I’ve used exactly the example from the guide, but I’m unable to create new entries via panel, no matter if mySQL or SQLite.
Editing and delelting works as expected.

Can someone point me to the right direction?
Thanks in advance
Chris

Just forgot to mention:

Kirby 3.9.6
php 8.1.12
Server nginx

Seems it breaks in line 14 in site\models\comment.php

return Db::insert('comments', $data);

Hi Christian, hm, I wonder if the data types are correct? Do you get any specific errors? Might make sense to try and print the last error. At least that’s the common reason why it fails.

Hi Sonja, data types are set like mentioned in the guide. I don’t get any error at all and I don’t know how to debug in the model.

I just set up a test with a fresh Starterkit and inserting works for me without any issues (but I run into issues when trying to change the slug). Well, I know this sort of answer doesn’t help you at all…

Do you use Ray (then you could install the plugin)? Or xDebug? Or try to log using error_log(), then check your PHP error log


$result =  Db::insert('comments', $data);
error_log($result);
error_log(Db::connection()->lastError());
return $result;

Just noticed that I have a different column setup, my table doesn’t use an id

Columns:
slug varchar(255) PK
user varchar(255)
text varchar(255)
status varchar(255)
title varchar(255)

Hi Sonja,
the error_log doesn’t show an error. I really do not know where to look anymore.

I’ve downloaded a fresh starterkit and used the db columns you mentioned above. The behavior ist the same. Deleting and editing works, creating new entries fails.

My test environment is a laravel valet (with nginx) on a mac. Did you test with Mysql or SQLite? I’ve tried both and none of them is working.

Maybe you could send me a mysql-dump or a sqlite-file of your test? It can actually only be a database issue.

PS: With the latest Kirby 4 alpha version (kirby-4.0.0-alpha.6), the example doesn’t work at all anymore.

It throws an exception:

Declaration of CommentsPage::children() must be compatible with Kirby\Cms\Page::children(): Kirby\Cms\Pages

MySQL. I’ll upload the dump somewhere and send you a link shortly.

That should be easy to fix, the signature of the children method must be the same as the parent method, so you have to add the return type

public function children(): Pages
1 Like

That helped, thanks a lot. The setup of my database was wrong. Columns may not be NOT NULL but DEFAULT NULL

The fix
public function children(): Pages
also fixed the exception with Kirby 4.