PHP Класс Tools\Model\Behavior\SluggedBehavior

Usage: See docs
Автор: Andy Dawson
Автор: Mark Scherer
Наследование: extends Cake\ORM\Behavior
Показать файл Открыть проект

Защищенные свойства (Protected)

Свойство Тип Описание
$_defaultConfig array - label: set to the name of a field to use for the slug, an array of fields to use as slugs or leave as null to rely on the format returned by find('list') to determine the string to use for slugs - field: The slug field name - overwriteField: The boolean field to trigger overwriting if "overwrite" is false - mode: has the following values ascii - retuns an ascii slug generated using the core Inflector::slug() function display - a dummy mode which returns a slug legal for display - removes illegal (not unprintable) characters url - returns a slug appropriate to put in a URL class - a dummy mode which returns a slug appropriate to put in a html class (there are no restrictions) id - retuns a slug appropriate to use in a html id - separator: The separator to use - length: Set to 0 for no length. Will be auto-detected if possible via schema. - overwrite: has 2 values false - once the slug has been saved, do not change it (use if you are doing lookups based on slugs) true - if the label field values change, regenerate the slug (use if you are the slug is just window-dressing) - unique: has 2 values false - will not enforce a unique slug, whatever the label is is direclty slugged without checking for duplicates true - use if you are doing lookups based on slugs (see overwrite) - case: has the following values null - don't change the case of the slug low - force lower case. E.g. "this-is-the-slug" up - force upper case E.g. "THIS-IS-THE-SLUG" title - force title case. E.g. "This-Is-The-Slug" camel - force CamelCase. E.g. "ThisIsTheSlug" - replace: custom replacements as array - on: beforeSave or beforeRules - scope: certain conditions to use as scope - tidy: If cleanup should be run on slugging
$_table Cake\ORM\Table Table instance

Открытые методы

Метод Описание
__construct ( Table $table, array $config = [] )
beforeRules ( Cake\Event\Event $event, Cake\ORM\Entity $entity ) : void SluggedBehavior::beforeRules()
beforeSave ( Cake\Event\Event $event, Cake\ORM\Entity $entity ) : void SluggedBehavior::beforeSave()
findSlugged ( Query $query, array $options ) : Query SluggedBehavior::findSlugged()
generateSlug ( string $value, Cake\ORM\Entity $entity = null ) : string Slug method
initialize ( array $config ) : void Constructor hook method.
needsSlugUpdate ( Cake\ORM\Entity $entity, boolean $deep = false ) : boolean Method to find out if the current slug needs updating.
resetSlugs ( array $params = [] ) : boolean ResetSlugs method.
slug ( Cake\ORM\Entity $entity, array $options = [] ) : void SluggedBehavior::slug()

Защищенные методы

Метод Описание
_multiSlug ( Cake\ORM\Entity $entity ) : void Multi slug method
_pregReplace ( string | array $pattern, string | array $replace, string $string ) : string Wrapper for preg replace taking care of encoding
_regex ( string $mode ) : string | null Regex method

Описание методов

__construct() публичный Метод

public __construct ( Table $table, array $config = [] )
$table Cake\ORM\Table
$config array

_multiSlug() защищенный Метод

Handle both slug and label fields using the translate behavior, and being edited in multiple locales at once FIXME
protected _multiSlug ( Cake\ORM\Entity $entity ) : void
$entity Cake\ORM\Entity
Результат void

_pregReplace() защищенный Метод

Wrapper for preg replace taking care of encoding
protected _pregReplace ( string | array $pattern, string | array $replace, string $string ) : string
$pattern string | array
$replace string | array
$string string
Результат string

_regex() защищенный Метод

Based upon the mode return a partial regex to generate a valid string for the intended use. Note that you can use almost litterally anything in a url - the limitation is only in what your own application understands. See the test case for info on how these regex patterns were generated.
protected _regex ( string $mode ) : string | null
$mode string
Результат string | null A partial regex or false on failure

beforeRules() публичный Метод

SluggedBehavior::beforeRules()
public beforeRules ( Cake\Event\Event $event, Cake\ORM\Entity $entity ) : void
$event Cake\Event\Event
$entity Cake\ORM\Entity
Результат void

beforeSave() публичный Метод

SluggedBehavior::beforeSave()
public beforeSave ( Cake\Event\Event $event, Cake\ORM\Entity $entity ) : void
$event Cake\Event\Event
$entity Cake\ORM\Entity
Результат void

findSlugged() публичный Метод

SluggedBehavior::findSlugged()
public findSlugged ( Query $query, array $options ) : Query
$query Cake\ORM\Query
$options array
Результат Cake\ORM\Query

generateSlug() публичный Метод

For the given string, generate a slug. The replacements used are based on the mode setting, If tidy is false (only possible if directly called - primarily for tracing and testing) separators will not be cleaned up and so slugs like "-----as---df-----" are possible, which by default would otherwise be returned as "as-df". If the mode is "id" and the first charcter of the regex-ed slug is numeric, it will be prefixed with an x. If unique is set to true, check for a unique slug and if unavailable suffix the slug with -1, -2, -3 etc. until a unique slug is found
public generateSlug ( string $value, Cake\ORM\Entity $entity = null ) : string
$value string
$entity Cake\ORM\Entity
Результат string A slug

initialize() публичный Метод

Implement this method to avoid having to overwrite the constructor and call parent.
public initialize ( array $config ) : void
$config array The configuration array this behavior is using.
Результат void

needsSlugUpdate() публичный Метод

The deep option is useful if you cannot rely on dirty() because of maybe some not in sync slugs anymore (saving the same title again, but the slug is completely different, for example).
public needsSlugUpdate ( Cake\ORM\Entity $entity, boolean $deep = false ) : boolean
$entity Cake\ORM\Entity
$deep boolean If true it will generate a new slug and compare it to the currently stored one.
Результат boolean

resetSlugs() публичный Метод

Regenerate all slugs. On large dbs this can take more than 30 seconds - a time limit is set to allow a minimum 100 updates per second as a preventative measure. Note that you should use the Reset behavior if you need additional functionality such as callbacks or timeouts.
public resetSlugs ( array $params = [] ) : boolean
$params array
Результат boolean Success

slug() публичный Метод

SluggedBehavior::slug()
public slug ( Cake\ORM\Entity $entity, array $options = [] ) : void
$entity Cake\ORM\Entity Entity
$options array Options
Результат void

Описание свойств

$_defaultConfig защищенное свойство

- label: set to the name of a field to use for the slug, an array of fields to use as slugs or leave as null to rely on the format returned by find('list') to determine the string to use for slugs - field: The slug field name - overwriteField: The boolean field to trigger overwriting if "overwrite" is false - mode: has the following values ascii - retuns an ascii slug generated using the core Inflector::slug() function display - a dummy mode which returns a slug legal for display - removes illegal (not unprintable) characters url - returns a slug appropriate to put in a URL class - a dummy mode which returns a slug appropriate to put in a html class (there are no restrictions) id - retuns a slug appropriate to use in a html id - separator: The separator to use - length: Set to 0 for no length. Will be auto-detected if possible via schema. - overwrite: has 2 values false - once the slug has been saved, do not change it (use if you are doing lookups based on slugs) true - if the label field values change, regenerate the slug (use if you are the slug is just window-dressing) - unique: has 2 values false - will not enforce a unique slug, whatever the label is is direclty slugged without checking for duplicates true - use if you are doing lookups based on slugs (see overwrite) - case: has the following values null - don't change the case of the slug low - force lower case. E.g. "this-is-the-slug" up - force upper case E.g. "THIS-IS-THE-SLUG" title - force title case. E.g. "This-Is-The-Slug" camel - force CamelCase. E.g. "ThisIsTheSlug" - replace: custom replacements as array - on: beforeSave or beforeRules - scope: certain conditions to use as scope - tidy: If cleanup should be run on slugging
protected array $_defaultConfig
Результат array

$_table защищенное свойство

Table instance
protected Table,Cake\ORM $_table
Результат Cake\ORM\Table