Создать
@param $slug
@return array|string|\yii\web\Response
501641
public function actionCreate($slug)
    {
        $current_model = $this->module->getModel($slug);

        if ($current_model->load(Yii::$app->request->post())) {
            if(Yii::$app->request->isAjax){
                Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
                return ActiveForm::validate($current_model);
            }
            else{
                if(isset($_FILES)){
                    $this->saveFiles($current_model);
                }

                if($current_model->save()){
                    $this->flash('success', Yii::t('gr', 'Post created'));
                    return $this->redirect([Url::previous()]);
                }
                else{
                    $this->flash('error', Yii::t('gr', 'Error'));
                    return $this->refresh();
                }
            }
        }
        else {
            return $this->render('@grozzzny/base_module/views/a/create', [
                'current_model' => $current_model
            ]);
        }
    }
666720
public function getBySlug($slug)
    {
        if (empty($slug))
            throw new Exception("Cannot retrieve object [".get_class($this->getModel())."] without slug");

        $results = $this->multiGetBySlug((array)$slug);
        if (isset($results[$slug]))
            return $results[$slug];

        throw new Exception(get_class($this->getModel()).' not found for slug: '.$slug);

    }
288493
public function show($slug)
	{
		try
		{
			return View::make($this->theme.'/pages/'.$slug);
		}
		catch (\InvalidArgumentException $e)
		{
			return App::abort(404, 'Page not found');
		}
	}
616116
public function postAction(Request $request, $slug)
    {
        // Получение $node_id
        $data = $request->request->all();
        $node_id = null;
        foreach ($data as $key => $value) {
            if ($key == '_node_id') {
                $node_id = $data['_node_id'];
                unset($data['_node_id']);
                break;
            }

            if (is_array($value) and array_key_exists('_node_id', $value)) {
                $node_id = $data[$key]['_node_id'];
                unset($data[$key]['_node_id']);
                break;
            }
        }

        foreach ($data as $key => $value) {
            $request->request->set($key, $value);
        }

        $node = $this->get('cms.node')->get($node_id);

        if (!$node instanceof Node or !$node->isActive()) {
            throw new AccessDeniedHttpException('Node is not active.');
        }

        // @todo сделать здесь проверку на права доступа, а также доступность ноды в запрошенной папке.

        // @todo сделать роутинги для POST запросов к нодам.
        return $this->forward("{$node->getId()}:{$node->getModule()}:post", ['slug' => $slug]);
    }
990021
public function actionView($id = null, $slug = null)
    {
        $model = User::find()->where(['and',
                ['id' => $id],
                ['!=', 'status', User::STATUS_REGISTERED],
                ['or',
                    ['slug' => $slug],
                    ['slug' => ''],
                    ['slug' => null],
                ]
            ])->limit(1)->one();
        if (empty($model)) {
            $this->error(Yii::t('podium/flash', 'Sorry! We can not find Member with this ID.'));
            return $this->redirect(['members/index']);
        }
        return $this->render('view', ['model' => $model]);
    }
389582
public static function findBySlug($slug)
    {
        $video = Video::find()
            ->with(['images' => function ($imageQuery) {
                $imageQuery->select(['image_id', 'video_id', 'filepath', 'source_url'])
                    ->indexBy('image_id');
            }])
            ->with(['categories' => function ($categoryQuery) {
                $categoryQuery->select(['category_id', 'title', 'slug', 'h1'])
                	->where(['enabled' => 1]);
            }])
            ->where(['slug' => $slug, 'status' => VideoStatus::PUBLISH])
            ->asArray()
            ->one();

            // постер для видео
        if (null !== $video && !empty($video['images'][$video['image_id']])) {
            $video['image'] = $video['images'][$video['image_id']];
        }

        return $video;
    }
542744
private function get_help_content( $slug ) {
		if ( empty( $slug ) ) {
			return '';
		}

		return $this->get_view( 'admin/help/' . $slug, $this->get_help_content_params(), false, false );
	}
729189
public function actionCreate( $slug ) {

        $post   = $this->modelService->getBySlug( $slug, true );

        $this->view->params[ 'model' ]  = $post;

        $this->view->params[ 'step' ]   = 'content';

        if( isset( $post ) ) {

            $model          = new Block();
            $modelBlock     = new ModelBlock();

            $model->siteId  = Yii::$app->core->site->id;

            if( $model->load( Yii::$app->request->post(), $model->getClassName() ) ) {

                $this->blockService->create( $model );

                $modelBlock->modelId    = $model->id;
                $modelBlock->parentId   = $post->id;
                $modelBlock->parentType = $post->type;

                $this->modelBlockService->create( $modelBlock );

                // Create Gallery
                $gallery            = new Gallery();
                $gallery->name      = $model->name;
                $gallery->siteId    = Yii::$app->core->siteId;
                $modelGallery       = $this->modelGalleryService->create( $gallery, [ 'parentId' => $model->id, 'parentType' => CmsGlobal::TYPE_BLOG_CONTENT ] );

                return $this->redirect( [ "update?slug=$model->slug&pslug=$post->slug" ] );
            }

            return $this->render( 'create', [
                'model' => $model,
                'post' => $post
            ] );
        }

        // Error- Page not found
		throw new NotFoundHttpException( Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_NOT_FOUND ) );
    }
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,
        ]);
    }
348469
public static function prefixSlug(string $slug) : string
    {
        if (substr($slug, 0, strlen(self::MODULE_PREFIX)) !== self::MODULE_PREFIX) {
            $slug = self::MODULE_PREFIX . $slug;
        }

        if (strlen($slug) > 20) {
            $slug = substr($slug, 0, 20);
        }

        $slug = strtolower($slug);

        return $slug;
    }
898396
public static function load(string $slug)
    {
        $instance = new static();

        $instance->route = [];
        $instance->route['slug'] = $slug;
        $instance->route['groups'] = collect([]);

        return $instance;
    }
403254
public function slug($slug = null)
    {
        if (null === $slug) {
            return $this->slug;
        }

        $this->slug = $slug;

        return $this;
    }
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();
    }
826857
public function actionSingle( $slug ) {

		$model = $this->formService->getBySlugType( $slug, CoreGlobal::TYPE_FORM );

		if( isset( $model ) ) {

			// Find Template
			$content	= $model->modelContent;
			$template	= $content->template;

			// Fields
			$formFields	= $model->getFieldsMap();

	 		$form	= new GenericForm( [ 'fields' => $formFields ] );
			$user	= Yii::$app->user->getIdentity();

			$form->captchaAction = '/cms/form/captcha';

			$this->view->params[ 'model' ] = $model;

			// Form need a valid user
			if( !$model->isVisibilityPublic() ) {

				// Form need it's owner
				if( $model->isVisibilityPrivate() && !$model->isOwner( $user ) ) {

					// Error- Not allowed
					throw new UnauthorizedHttpException( Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_NOT_ALLOWED ) );
				}

				// Form need logged in user
				if( $model->isVisibilityProtected() && empty( $user ) ) {

					// Remember URL for Login
					Url::remember( Url::canonical(), CoreGlobal::REDIRECT_LOGIN );

					// Error- Not allowed
					return $this->redirect( [ '/login' ] );
				}
			}

			if( $model->captcha ) {

				$form->setScenario( 'captcha' );
			}

			if( $form->load( Yii::$app->request->post(), 'GenericForm' ) && $form->validate() ) {

				// Save Model
				if( $this->formService->processForm( $model, $form ) ) {

					// Trigger User Mail
					if( $model->userMail ) {

						Yii::$app->formsMailer->sendUserMail( $model, $form );
					}

					// Trigger Admin Mail
					if( $model->adminMail ) {

						Yii::$app->formsMailer->sendAdminMail( $model, $form );
					}

					// Set success message
					if( isset( $model->success ) ) {

						Yii::$app->session->setFlash( 'message', $model->success );
					}

					// Refresh the Page
		        	return $this->refresh();
				}
			}

			// Fallback to default template
			if( empty( $template ) ) {

				$template = $this->templateService->getGlobalBySlugType( FormsGlobal::TEMPLATE_FORM, CoreGlobal::TYPE_FORM );
			}

			if( isset( $template ) ) {

				return Yii::$app->templateManager->renderViewPublic( $template, [
		        	'model' => $model,
					'form' => $form,
					'content' => $content,
					'banner' => $content->banner
		        ], [ 'page' => true ] );
			}

	        return $this->render( CoreGlobalWeb::PAGE_INDEX, [
				'model' => $model,
				'form' => $form
	        ]);
		}

		// Model not found
		throw new NotFoundHttpException( Yii::$app->coreMessage->getMessage( CoreGlobal::ERROR_NOT_FOUND ) );
	}
746385
public function getLog($slug)
    {
        foreach ($this->logs as $log) {
            if ($log->getSlug() == $slug) {
                return $log;
            }
        }
    }
133965
protected function fixSlug($slug)
    {
        $parts = explode('/', $slug);
        $slug = '';
        foreach ($parts as $part) {
            if ($part) {
                $slug .= '/'.str_slug($part);
            }
        }

        return strtolower('/'.ltrim($slug, '/'));
    }
487942
public function findBySlug($slug)
    {
        return $this->slugWorkingRecord->get()->filter($this->slugDbField, $slug)->first();
    }