public function actionIndex($lang = null, $path = null) { $categoryIds = []; /** @var $category CategoryRecord*/ $category = null; if (empty($path)) { $categoryList = CategoryRecord::find()->select('id')->lang($lang)->all(); foreach ($categoryList as $categoryItem) { $categoryIds[] = $categoryItem->id; } } else { $categoryModel = new CategoryRecord(); $category = $categoryModel->findByFullPath($path); if (!$category) { throw new HttpException(404, 'Категория не найдена'); } $categoryList = $category->childrens(); $categoryIds[] = $category->id; foreach ($categoryList as $categoryItem) { $categoryIds[] = $categoryItem->id; } } $productList = ProductRecord::find()->lang($lang)->andWhere(['categoryId' => $categoryIds])->all(); $template = $category->templateList ? $category->templateList : 'default'; return $this->render('index/' . $template, ['category' => $category, 'productList' => $productList]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = CategoryRecord::find()->lang(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'parentId' => $this->parentId]); $query->andFilterWhere(['like', 'lang', $this->lang])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'metaKeywords', $this->metaKeywords])->andFilterWhere(['like', 'metaDescription', $this->metaDescription]); return $dataProvider; }
<?php use yii\jui\Accordion; /* @var $this yii\web\View */ /* @var $model app\modules\catalog\models\ProductRecord */ /* @var $form yii\widgets\ActiveForm */ $category = \app\modules\catalog\models\CategoryRecord::find()->one(); ?> <div class="product-record-form"> <div class="well"> <div class="row"> <div class="col-md-6"> <?php echo $form->field($model, '[' . $k . ']title')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, '[' . $k . ']kolvoKomnat')->textInput(); ?> </div> <?php if ($model->isCurrentLang()) { ?> <div class="col-md-6"> <?php echo $form->field($model, '[' . $k . ']alias')->textInput(['maxlength' => true]); ?> </div> <?php
public function run() { $categoryList = CategoryRecord::find()->lang(\Yii::$app->language)->andWhere(['parentId' => '0'])->all(); return $this->render($this->template, ['categoryList' => $categoryList]); }