src/Model/Behavior/SluggableBehavior.php
private function slug($value = null) {
        // generate slug
        $slug = strtolower(Text::slug($value, $this->_config['replacement']));

        // unique slug?
        if($this->_config['unique']) {
            // does the slug already exist?
            $field = $this->_table->getAlias() . '.slug';
            $conditions = [$field => $slug];
            $suffix = '';
            $i = 0;

            // loop till unique slug is found
            while ($this->_table->exists($conditions)) {
                $i++;
                $suffix = $this->_config['replacement'] . $i;
                $conditions[$field] = $slug . $suffix;
            }

            // got suffix? append it
            if($suffix)
                $slug .= $suffix;
        }

        // return slug
        return $slug;
    }
private function slug($value = null) {
        // generate slug
        $slug = strtolower(Text::slug($value, $this->_config['replacement']));

        // unique slug?
        if($this->_config['unique']) {
            // does the slug already exist?
            $field = $this->_table->getAlias() . '.slug';
            $conditions = [$field => $slug];
            $suffix = '';
            $i = 0;

            // loop till unique slug is found
            while ($this->_table->exists($conditions)) {
                $i++;
                $suffix = $this->_config['replacement'] . $i;
                $conditions[$field] = $slug . $suffix;
            }

            // got suffix? append it
            if($suffix)
                $slug .= $suffix;
        }

        // return slug
        return $slug;
    }
private function slug ( $ value = null ) { // generate slug $ slug = strtolower ( Text :: slug ( $ value , $ this -> _config [ 'replacement' ] ) ) ; // unique slug? if ( $ this -> _config [ 'unique' ] ) { // does the slug already exist? $ field = $ this -> _table -> getAlias ( ) . '.slug' ; $ conditions = [ $ field => $ slug ] ; $ suffix = '' ; $ i = 0 ; // loop till unique slug is found while ( $ this -> _table -> exists ( $ conditions ) ) { $ i ++ ; $ suffix = $ this -> _config [ 'replacement' ] . $ i ; $ conditions [ $ field ] = $ slug . $ suffix ; } // got suffix? append it if ( $ suffix ) $ slug .= $ suffix ; } // return slug return $ slug ; }
Slug a field passed in the default config with its replacement.
@param string $value The string that needs to be processed
@return string
Slug a field passed in the default config with its replacement .