/** * Generate a slug from a base string that is unique in the database * @param String $base * @param Model $model Model object of this record * @param String $slugField Name of the slug column in the database * @param String $lang Optional language. Used with internationalized models * @return String $slug The generated unique slug */ public function generateUniqueSlug($base, $model, $slugField, $lang = null) { $slug = $this->generateSlug($base); $select = $model->getAdapter()->select()->from($model->getName(), 'COUNT(*)'); $this->_setWhereClause($select, $slugField, $slug, $model, $lang); $n = 1; while ($this->_rowsExist($select)) { $this->_incrementSlug($slug, ++$n, $base); $this->_setWhereClause($select, $slugField, $slug, $model, $lang); } return $slug; }