Database connection and images

Hey! I’ve successfully connected a database to create virtual pages (there’s many database entries and it makes sense to do this as a database instead of real content pages) but I’m unsure how to handle images.

It seems that when uploading an image a new folder gets created but no direct link to the uploaded image is provided, instead having a field save to the database saves a vague reference. How would I be able to integrate images because as it stands now the database connection doesn’t really serve much purpose speed-wise if it doesn’t work well with images.

Thank you!

Yes, images are store in a page folder, and to make this work you would have to merge content stored in the database with content from the filesystem: Merging content sources | Kirby CMS

We do that on the Kirby website to enhance the auto-generated documentation from Reflections with example code or images.

Note that the documentation doesn’t take in mind handling all this through the Panel, so you need to extend the models, especially if you want to deal with changing the slug, status etc.

Of course, instead of storing the images in the file system, you could store them somewhere in the cloud and store the reference to the image in the database.

While using a database to deal with a lot of data on the frontend may make sense when you just query the data you need, using them as virtual pages will not result in a performance gain.

Thanks for the answer! I’m a little confused however what you mean by this. We need a Kirby site that has some normal page but also has an archive that has about 2,000 pages. Wouldn’t making those 2,000 pages virtual pages and a database connection speed-up things?

The problem is that with the children() method you load all database entries into memory at once. So a flat structure with only one parent can result in a bottleneck, and a tree-like structure would be better suited.

2000 articles could still be fast enough (at least worth a test), but will depend on the resources on your server, so I’d probably not do this on cheap shared hosting.