Is there an unchanging, unique ID field in a page? - i.e., something that is not going to change if the user changes the pageās title, or content?
Is any one of these an unchanging, unique id?:
$page->uid()
$page->hash()
$page->uri()
Any guidance would be much appreciated!
Ok, just did some testing, and it seems that all 3 provide values that do not change after the page is created. Can someone please confirm that this is the case?..
If you change the page slug/URL, these change too. There is no permanent ID / link in Kirby.
Iām not sure what you need it for, but @lukasbestle suggested a ārole fieldā in this post Prevent user from changing page slug in panel which might be a good idea to use, especially if it is hidden and canāt be changed by the user. You might as well use such a field for a unique id.
@texnixe I am adding Disqus to blog articles. Disqus works best if we can provide a unique id that identifies the blog article, and fetches all the comments that belong to it. If we donāt provide an explicit id, itāll use the pageās url - which can be arbitrarily changed by the user (if they change the slug)ā¦
CMSs that use a backend database usually generate a unique id automatically for every record on a table, and that is what is normally used. In Kirby, things are a bit different, so I donāt quite know how to go about itā¦
Maybe read this thread a lil: Biggest Advantage of Kirby
Thank you for the link, @distantnative - itās indeed an interesting thread, and the discussion about the lack of primary keys helped.
I wonder how difficult it would be to implement a āuuidā custom field? - ie. a field that would automatically generate a uuid, and not be editable in the panel?
You could hack it with in()
, but thatās not very elegant. It seems like a editable: false
parameter would be useful for blueprint files.
Youād still have to write the uuid
manually, too.
PHP has a built-in uuid function - itās not cryptographically secure, but more than sufficient for our purposes here. If something better is required, look at the comments in that manual page - the second comment has a complete and fully standards-compliant UUID class, ready to be used.
So, generating the uuid wouldnāt be too much of an issue. But how to add that value to a display-only field at page-creation time? Maybe this requires a custom field to be written.
Hm, you can loose or want to modify page creation times as well sometimes (like when importing blogs).
What I thought of, if youāre only using the panel, is supplying a sort of subpage-builder for id templates with ineditable/undeletable fields that holds nothing but the id ā like this
/content/1-about/1-my-page/id
Didnāt test it though.