Положить модель с алиасом
@param ActiveRecord $model Модель к которой принадлежит алиас
@param SeoSlug $slug Модель с алиасом которую нужно закешировать
@return mixed
766718
public function set(ActiveRecord $model, SeoSlug $slug)
    {
        $key = $model::className() . '-' . $model->getPrimaryKey();
        $this->_storage[$key] = $slug;
    }
736411
public function scopeWhereSlug(Builder $scope, string $slug): Builder
    {
        return $scope->where($this->getSlugKeyName(), $slug);
    }
56438
public static function checkSlug($slugField, $slug, $id = null)
    {
        $instance   = new static;

        $slug   = $slug;
        $query = $instance->where($slugField, $slug);

        if($id != null)
        {
            $query->whereNotIn($instance->getKeyName(), [$id]);
        }

        $nObjects = $query->count();

        if($nObjects > 0)
        {
            $suffix = 0;
            while($nObjects > 0)
            {
                $suffix++;
                $slug       = $slug . '-' . $suffix;
                $nObjects   = $instance->where($slugField, $slug)->count();
            }
        }

        return $slug;
    }
1129258
public static function findBySlug($slug, $columnName = '')
    {
        $userObj = User::where('slug', $slug)->first();

        // return custom column
        if ($columnName && isset($userObj->$columnName)) {
            return $userObj->$columnName;
        }

        return $userObj;
    }
795269
public function delete($slug)
    {
        if(is_object($slug) && $slug instanceof ModelObject)
            $slug = $slug->Slug;

        $this->Events->trigger(get_class($this).'.delete.pre', $this, $slug);
        $this->Events->trigger('AbstractSystemXMLDAO.delete.pre', $this, $slug);

        $this->loadSource();

        if(isset($this->objectsBySlug[$slug]))
        {
            $obj = $this->objectsBySlug[$slug];

            unset($this->objectsBySlug[$slug]);
            unset($this->slugsByID[$obj->AspectID]);

            $pKey = array_search($slug, $this->slugsByPluginID[$obj->PluginID]);
            unset($this->slugsByPluginID[$pKey]);

        }

        $this->persistSource();

        $this->Events->trigger(get_class($this).'.delete.post', $this, $slug);
        $this->Events->trigger('AbstractSystemXMLDAO.delete.post', $this, $slug);

        return true;
    }
649486
public function slugExists(Model $model, $slug) {
        return (bool) $model->find('count', array(
            'conditions' => array($this->settings[$model->alias]['slug'] => $slug),
            'recursive' => -1,
            'contain' => false
        ));
    }
742713
public static function findBySlugOrFail($slug, array $columns = ['*'])
    {
        // Model not found, throw exception
        if (!$item = static::findBySlug($slug)) {
            throw (new ModelNotFoundException)->setModel(get_called_class());
        }

        // Return the model if visible
        $item->enforceVisibility();

        return $item;
    }
853308
public function actionViewBySlug($slug)
    {
        $lh = $this->module->langHelper;
        $language = $lh::normalizeLangCode(Yii::$app->language);

        $model = null;
        $modelI18n = $this->module->model('NewsI18n')->findOne([
            'slug' => $slug,
            'lang_code' => $language,
        ]);

        // but after language switching slug for article on another language can be another
        if (empty($modelI18n)) {  // try to get language from referer
            $referer = Yii::$app->request->referrer;
            $hostInfo = Yii::$app->request->hostInfo;
            if (0 === strpos($referer, $hostInfo)) {
                $previousLanguage = substr($referer, strlen($hostInfo) + 1, 2);
                $previousLanguage = $lh::normalizeLangCode($previousLanguage);
                $modelI18n = $this->module->model('NewsI18n')->findOne([
                    'slug' => $slug,
                    'lang_code' => $previousLanguage,
                ]);
                if (!empty($modelI18n)) {  // found i18n-model for previous language
                    $model = $modelI18n->getMain()->one();  // get common model
                    if (!empty($model)) {
                        $modelsI18n = $model::prepareI18nModels($model);
                        if (!empty($modelsI18n[$language])) {
                            // do now show page with illegal slug in URL - prepare to redirect with correct slug
                            $newSlug = $modelsI18n[$language]->slug;
                            $result = Yii::$app->getUrlManager()->parseRequest(Yii::$app->request);
                            if (is_array($result)) {
                                list ($route, $routeParams) = $result;
                                $routeParams[0] = $route;
                                $routeParams['lang'] = $language;
                                $routeParams['slug'] = $newSlug;
                                $link = Yii::$app->urlManager->createUrl($routeParams);
                                return $this->redirect($link);
                            }                
                        }
                    }
                }
            }
        }
        
        if (!empty($modelI18n)) {
            $contentHelper = new $this->contentHelperClass;
            $modelI18n->body = $contentHelper::afterSelectBody($modelI18n->body);
            $model = $modelI18n->getMain()->one();
        }

        $searchModel = $this->module->model('NewsSearchFront');
        $model = $searchModel::canShow($model, $modelI18n);
        if (!$model) {
            $modelI18n = false;
        }

        return $this->render('view', compact('model', 'modelI18n'));
    }
326523
public function beforeSave(Model $model, $options = array()) {
		$fields = (array)$this->__settings[$model->alias]['fields'];
		$scope = (array)$this->__settings[$model->alias]['scope'];
		$conditions = !empty($this->__settings[$model->alias]['conditions']) ? (array)$this->__settings[$model->alias]['conditions'] : array();
		$slugfield = $this->__settings[$model->alias]['slugfield'];
		$hasFields = true;

		foreach ($fields as $field) {
			if (!$model->hasField($field)) {
				$hasFields = false;
			}

			if (!isset($model->data[$model->alias][$field])) {
				$hasFields = false;
			}
		}

		if ($hasFields && $model->hasField($slugfield) && ($this->__settings[$model->alias]['overwrite'] || empty($model->id))) {
			$toSlug = array();

			foreach ($fields as $field) {
				$toSlug[] = $model->data[$model->alias][$field];
			}

			$toSlug = join(' ', $toSlug);

			$slug = Inflector::slug($toSlug, $this->__settings[$model->alias]['separator']);

			if ($this->__settings[$model->alias]['lower']) {
				$slug = strtolower($slug);
			}

			if (strlen($slug) > $this->__settings[$model->alias]['length']) {
				$slug = substr($slug, 0, $this->__settings[$model->alias]['length']);
			}

			$conditions[$model->alias . '.' . $slugfield . ' LIKE'] = $slug . '%';

			if (!empty($model->id)) {
				$conditions[$model->alias . '.' . $model->primaryKey . ' !='] = $model->id;
			}

			if (!empty($scope)) {
				foreach ($scope as $s) {
					if (isset($model->data[$model->alias][$s])) {
						$conditions[$model->alias . '.' . $s] = $model->data[$model->alias][$s];
					}
				}
			}

			$sameUrls = $model->find('all', array(
				'recursive' => -1,
				'conditions' => $conditions
			));

			$sameUrls = (!empty($sameUrls))
				? Hash::extract($sameUrls, '{n}.' . $model->alias . '.' . $slugfield)
				: array();

			if (!empty($sameUrls)) {
				if (in_array($slug, $sameUrls)) {
					$begginingSlug = $slug;
					$index = 1;

					while ($index > 0) {
						if (!in_array($begginingSlug . $this->__settings[$model->alias]['separator'] . $index, $sameUrls)) {
							$slug = $begginingSlug . $this->__settings[$model->alias]['separator'] . $index;
							$index = -1;
						}

						$index++;
					}
				}
			}

			$model->data[$model->alias][$slugfield] = $slug;
		}

		return parent::beforeSave($model);
	}
1293758
private function getSimilarSlugs(EntityManager $em, $slug)
    {
        if (!isset($this->similarSlugs[$slug])) {
            $this->similarSlugs[$slug] = $this->getSlugMapItemRepository($em)->getSimilarSlugs($slug);
        }

        return $this->similarSlugs[$slug];
    }
208738
public static function getBySlug($slug)
    {
        $slug_parts = explode("-", $slug, 2);
        $class = get_called_class();
        $temp_this = new $class();
        $primary_key = $temp_this->getIDField();
        return self::search()->where($primary_key, $slug_parts[0])->execOne();
    }
1195174
public function getGlobalBySlugType( $slug, $type, $config = [] ) {

		$modelClass = static::$modelClass;

		return $modelClass::findGlobalBySlugType( $slug, $type, $config );
	}
487942
public function findBySlug($slug)
    {
        return $this->slugWorkingRecord->get()->filter($this->slugDbField, $slug)->first();
    }
446426
public function getWithContent( $id, $slug = null ) {

		$modelClass	= static::$modelClass;
		$modelTable	= $this->getModelTable();

		if( isset( $slug ) ) {

			return $modelClass::queryWithContent( [ 'conditions' => [ "$modelTable.slug" => $slug ] ] )->one();
		}

		return $modelClass::queryWithContent( [ 'conditions' => [ "$modelTable.id" => $id ] ] )->one();
	}
1019426
public function listByCategoryAction(Request $request, $slug)
    {
        $em = $this->getDoctrine()->getManager();

        /* seo metadata */
        $seoPage = $this->container->get('sonata.seo.page');
        $baseTitle = $seoPage->getTitle();
        $title = "Productos - " . $baseTitle;
        $seoPage->setTitle($title);

        /* pagination */
        $pageNumber = $request->get("page", 1);
        $products = $this->getDoctrine()->getRepository("AmulenShopBundle:Product")->findEnabledByPageAndCategory($slug);
        $paginator = $this->get('knp_paginator');
        $pagination = $paginator->paginate($products, $this->get('request')->query->get('page', $pageNumber), 2);

        return array(
            'pagination' => $pagination,
        );
    }
1216037
public function findOneBySlug($slug)
    {
        $query = $this->createQueryBuilder('c')
            ->where('c.slug = :slug')
            ->setParameter('slug', $slug)
            ->andWhere('c.publishAt < :now OR c.publishAt IS NULL')
            ->andWhere('c.active = :active')
            ->andWhere('c.layout = :layout')
            ->setParameter('now', new \DateTime())
            ->setParameter('active', true)
            ->setParameter('layout', false)
            ->setMaxResults(1)
            ->getQuery();

        return $query->useResultCache(true, self::CACHE_TTL)->getOneOrNullResult();
    }
59721
public function actionIndex($slug, $page = 1, $sort = '')
    {
        $this->trigger(self::EVENT_BEFORE_CATEGORY_SHOW);

        $data['slug'] = $slug;
        $data['sort'] = $sort;
        $data['page'] = (int) $page;
        $data['route'] = '/' . $this->getRoute();

        	// Ищем категорию
        $data['category'] = CategoryFinder::findBySlug($slug);//$categriesRepository->findBySlug($slug);

		if (empty($data['category'])) {
			throw new NotFoundHttpException('The requested page does not exist.');
		}

        $videoFinder = new VideoFinder();
        $data['videos'] = $videoFinder->getVideosFromCategory($data['category'], $page);

        $pagination = new Pagination([
            'totalCount' => $videoFinder->totalCount(),
            'defaultPageSize' => Module::getInstance()->settings->get('items_per_page', 20),
            'pageSize' => Module::getInstance()->settings->get('items_per_page', 20),
            'route' => $data['route'],
            'forcePageParam' => false,
        ]);

        $settings = Yii::$app->settings->getAll();
        $settings['videos'] = Module::getInstance()->settings->getAll();

        Event::on(self::class, self::EVENT_AFTER_CATEGORY_SHOW, [\ytubes\videos\events\UpdateCountersEvent::class, 'onShowThumbs'], $data);

        $this->trigger(self::EVENT_AFTER_CATEGORY_SHOW);

        return $this->render('category_videos', [
            'data' => $data,
            'settings' => $settings,
            'pagination' => $pagination,
        ]);
    }