Slug
in package
Generate and validate slugs - i.e. unique, SEO-friendly URL segments.
See e.g. https://en.wikipedia.org/wiki/Semantic_URL#Slug
Table of Contents
Methods
- create() : string
- Create a slug, and ensure it's unique
- get() : array<string|int, mixed>
- Return all columns for a single row of a table (similar to {@see Pdb::get}) The row is specified using its slug.
- unique() : void
- Verify that a slug is unique for a given table
- valid() : mixed
- Verify that a slug contains only valid characters
Methods
create()
Create a slug, and ensure it's unique
public
static create(string $table, string $name) : string
Parameters
- $table : string
-
The table the item is on
- $name : string
-
The name of the item
Return values
string —The generated slug, should always be unique
get()
Return all columns for a single row of a table (similar to {@see Pdb::get}) The row is specified using its slug.
public
static get(string $table, string $slug[, array<string|int, mixed> $conditions = [] ]) : array<string|int, mixed>
Parameters
- $table : string
-
The table name, not prefixed
- $slug : string
-
The slug of the record to fetch
- $conditions : array<string|int, mixed> = []
-
Extra WHERE clause conditions if required, in the format prescribed by Pdb::buildClause
Tags
Return values
array<string|int, mixed> —The record data
unique()
Verify that a slug is unique for a given table
public
static unique(string $value, string $table[, array<string|int, mixed> $conditions = [] ]) : void
Parameters
- $value : string
-
The slug
- $table : string
-
The table to check, which must contain columns 'id', 'name', and 'slug'
- $conditions : array<string|int, mixed> = []
-
Extra conditions to check, in the format prescribed by Pdb::buildClause
Tags
valid()
Verify that a slug contains only valid characters
public
static valid(string $value) : mixed
Parameters
- $value : string
-
The slug