Esempio n. 1
0
 public function actionIndex($slug)
 {
     $category = CatalogCategories::find()->where(['slug' => $slug])->one();
     if (!$category) {
         throw new \yii\web\NotFoundHttpException(\Yii::t('app', 'Page not found'));
     }
     /*    $dataProvider = new \app\modules\catalog\components\CatalogDataProvider([
                'category_id' => $category->id,
                'pagination' => [
           //         'pageSize' => 1,
                ],
            ]);*/
     $cs = new CatalogSearch();
     // return $this->render('index',[ 'model' => $category, 'dataProvider' => $dataProvider ]);
     $searchModel = new CatalogSearch(['category_id' => $category->id]);
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     /*  return $this->render('/position/index', [
             'category' => $category,
             'searchModel' => $searchModel,
             'dataProvider' => $dataProvider,
         ]);*/
     $options = ['category' => $category, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider];
     if (Yii::$app->request->isPjax) {
         return $this->renderAjax('/position/index', $options);
     } else {
         return $this->render('/position/index', $options);
     }
 }
Esempio n. 2
0
 /**
  * Списочный вывод каталога
  * @param null|string $section символьный код категории каталога
  * @return string
  * @throws \yii\base\InvalidConfigException
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionIndex($section = null)
 {
     $cacheId = $this->getActionCacheId(static::LIST_CACHE_ID);
     $res = Yii::$app->cache->get($cacheId);
     $model = Yii::createObject(['class' => Catalog::className()]);
     $searchModel = Yii::createObject(['class' => CatalogSearch::className(), 'scenario' => ActiveRecord::SCENARIO_SEARCH]);
     $filter = $searchModel->load(Yii::$app->request->get());
     if (empty($res) or $filter) {
         $dependency = Yii::createObject(TagDependency::className());
         $res["sectionModel"] = null;
         if (empty($searchModel->sectionsIds) and $section) {
             $res["sectionModel"] = CatalogSection::find()->published()->andWhere(["code" => $section])->one();
             if (!$res["sectionModel"]) {
                 throw new NotFoundHttpException();
             }
             $dependency->addTag($res["sectionModel"]->setItemTagSafe());
             $searchModel->sectionsIds = $res["sectionModel"]->getFilterIds();
         }
         $dataProvider = $searchModel->publicSearch();
         $dataProvider->getSort()->defaultOrder = $this->orderBy;
         $dataProvider->getPagination()->pageSize = $this->pageSize;
         $dependency->addTag($model->setClassTagSafe());
         $dependency->setTagsFromModels($dataProvider->getModels());
         $res["html"] = $this->renderPartial('_grid', ["dataProvider" => $dataProvider, "previewImageWidth" => $this->previewImageWidth]);
         if (!$filter) {
             Yii::$app->cache->set($cacheId, $res, Yii::$app->params["cacheDuration"], $dependency);
         }
     }
     $this->view->addBreadCrumb(["label" => Yii::t('catalog/app', 'Catalog'), "url" => Url::toRoute(["/catalog/catalog/index"])]);
     if ($res["sectionModel"]) {
         $this->view->registerMetaTags($res["sectionModel"]);
         $crumbs = $res["sectionModel"]->getBreadCrumbsItems($res["sectionModel"]->id, function ($model) {
             return ['/catalog/catalog/index', 'section' => $model->code];
         });
         $this->view->addBreadCrumbs($crumbs);
     }
     return $this->render("index", ["sectionModel" => $res["sectionModel"], "model" => $model, "searchModel" => $searchModel, "html" => $res["html"]]);
 }
Esempio n. 3
0
 /**
  * Finds the Catalog model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Catalog the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CatalogSearch::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }