Virtual pages from database question

I’m testing the example which is explained here:

But i’m not able to add extra subpages via the add-button in the panel. I get an error ‘The page “comments/newpage” cannot be found’.

Should i add additional code to get this working?

Thanks

Not quite sure if that’s the problem, but the current version (3.2.x) doesn’t play nicely with virtual pages in the Panel because of content locking.

I’m testing in 3.1.3

Hm, I’d have to look into this later.

Hi texnixe,
i’m using the virtual pages (as explained in the kirby docs) now in a new project (k3.2). Everything seems to work fine, except that i can’t make any new pages… Any idea what could be the problem?

thanks

Are you using the plugin as suggested here: https://github.com/getkirby/kirby/issues/1900? Because in 3.2 there’s a problem with Content Locking and Virtual Pages

Apart from that, tthe example from the cookbook should work fine (only not in 3.2 without the locking disabler plugin), at least when I tested it again a couple of days ago and then forgot to get back to you.

@kmajort
I think there is indeed tricky things going on, I encountered myself.
Could you post your exact setup for the page models as well as your database structure please?

Could you elaborate a bit what these are, please?

I had on my passport site a similar issue, if I remember correctly. In the end it was tied to not matching the slug/id in the database right. I ended up writing a custom version of the pages section: https://github.com/distantnative/passport/tree/master/site/plugins/section-trips

But we would need to have a closer look at the database structure and page models to see if there is anything on @kmajort’s side to do or if it’s something wrong with Kirby.

Hi,
i made the it now work.
For some reasons this doesn’t work for me (in the model):

$data['slug'] = $this->slug();
return Db::insert('comments', $data);

but when i change it to this it works

return Db::insert('comments', ["slug"=>$this->slug()]);

Is there a way to change the slug before writing it to the database? (I need to add a specific number to that page)?
When i change the slug and insert it to the database, it redirects to the initially slug (page) which does not exist.

Do you only want to change what is stored in the database or actually change the page slug?

I want to change the page slug.

You can do that using the $page->changeSlug() method but note that if you do that programmatically rather than by using the changeUrl() option in the Panel, the user is not redirected to the new location.

It seems these things doesn’t work with virtual pages.

Oh, yes, that makes sense (unless you create a model method). Actually, if you just change what is stored in the database should do the job. Nonetheless, the Url will change and the user will get an error message in the Panel.

I wonder if it would be possible to change $this->slug() somehow before inserting the new item in the database, because i think that is the page kirby automatically forward to?