WireNumberTools::uniqueNumber() method

Generate and return an installation unique number/ID (integer)

  • Numbers returned by this method are incrementing, starting from 1.
  • Unique number counter stored in the database so is unique aross all time/requests.
  • Returned number is guaranteed to be unique among other calls to this method.
  • When using the namespace option, it will generate a new DB table for that namespace.
  • Use the reset option to delete a namespace when no longer needed.
  • You cannot reset the default namespace, so any caller is always assured a unique number.
  • This method creates table names that begin with unique_num.

Available since version 3.0.213.

Usage

// basic usage
$int = $wireNumberTools->uniqueNumber();

// usage with all arguments
$int = $wireNumberTools->uniqueNumber($options = []);

Arguments

NameType(s)Description
options (optional)array, string

Array of options or string for the namespace option.

  • namespace (string): Optional namespace for unique numbers, in table name format [_a-zA-Z0-9] (default='')
  • getLast (bool): Get last unique number rather than generating new one? (default=false)
  • reset (bool): Reset numbers in namespace by deleting its table? Namespace required (default=false)

Return value

int

Returns unique number, or returns 0 if reset option is used, or returns 0 if getLast option is used and no numbers exist.

Exceptions

Method can throw exceptions on error:

  • WireException


WireNumberTools methods and properties

API reference based on ProcessWire core version 3.0.236

Latest news

  • ProcessWire Weekly #543
    In the 543rd issue of ProcessWire Weekly we'll check out the latest weekly update from Ryan, introduce a couple of new third party modules — both authored by Bernhard Baumrock — and more. Read on!
    Weekly.pw / 5 October 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • Subscribe to weekly ProcessWire news

“We chose ProcessWire because of its excellent architecture, modular extensibility and the internal API. The CMS offers the necessary flexibility and performance for such a complex website like superbude.de. ProcessWire offers options that are only available for larger systems, such as Drupal, and allows a much slimmer development process.” —xport communication GmbH