Skip to content
This repository has been archived by the owner on Dec 11, 2022. It is now read-only.
hperrin edited this page Nov 5, 2014 · 9 revisions

UIDs, or unique IDs, provide an easier way for users to identify entities. UIDs are just sequential numbers and can be used for anything you like, not just entities. As opposed to a GUID, which is a unique ID for all entities, a UID is only unique for its own sequence. Therefore, they are more visually appealing to be used as an ID. (Think Sale #15 vs Sale #9007199254740991)

UIDs can be named anything. A good naming convention, in order to avoid conflicts, is to use your app's name, a slash, then a descriptive name of the sequence being identified for non-entity sequences or the name of the entity's class for entity sequences. E.g. "Blog/visitors" or "Blog/Post".

Nymph has the following methods for handling UIDs:

  • deleteUID - Delete a unique ID from the system.
  • getUID - Get the current value of a unique ID.
  • newUID - Increment or create a unique ID and return the new value.
  • renameUID - Rename a unique ID.
  • setUID - Set the value of a unique ID.
Using UIDs
```php $nymph = RPHP::_('Nymph');

// Create a new entity. $entity = Post::factory();

// Now give it a more friendly ID than GUID. $entity->id = $nymph->newUID('Blog/Post'); $entity->save();

```js
var entity = new Post();

Nymph.newUID('Blog/Post').then(function(uidValue){
  entity.set('id', uidValue);
  entity.save();
});

⚠️ Caution: If a UID is incremented, and the entity cannot be saved, there is no safe way to decrement the UID back to its previous value.

Clone this wiki locally