Documentation

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
throws
RowMissingException

If the record wasn't found

QueryException

if the query failed

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
example

// Exclude the current record when checking uniqueness $valid->check('slug', 'Slug::unique', 'pages', [['id', '!=', $page_id]]);

throws
ValidationException

If the slug isn't unique in the table under the specified conditions

InvalidArgumentException

If the $table argument is not a valid table name

valid()

Verify that a slug contains only valid characters

public static valid(string $value) : mixed
Parameters
$value : string

The slug

Tags
example

$valid->check('slug', 'Slug::valid');

throws
ValidationException
On this page

Search results