예제 #1
0
 public function actionAbc($a, $b, $c)
 {
     if (($app = Applications::find()->where(['name' => $a])->one()) !== null) {
         if (($parent_cat = Categories::find()->where(['app_id' => $app->id, 'alias' => $b])->one()) !== null) {
             // приложение -> категория по алиасу
             if (($category = Categories::find()->where(['app_id' => $app->id, 'parent_id' => $parent_cat->id, 'alias' => $c])->one()) !== null) {
                 return $this->renderCategory($category);
             } elseif (($model = Items::find()->where(['app_id' => $app->id, 'alias' => $c])->one()) !== null) {
                 // приложение -> материал по алиасу
                 return $this->renderItem($model);
             } elseif (($model = Items::find()->where(['app_id' => $app->id, 'id' => $c])->one()) !== null) {
                 // приложение -> материал по ID
                 return $this->renderItem($model);
             }
         }
     } else {
         if (($category = Categories::find()->where(['app_id' => 1, 'alias' => $a])->one()) !== null) {
             if (($model = Items::find()->where(['app_id' => 1, 'alias' => $b])->one()) !== null && $model->parentCategory->alias == $a) {
                 // приложение -> материал по алиасу
                 return $this->renderItem($model);
             } elseif (($model = Items::find()->where(['app_id' => 1, 'id' => $b])->one()) !== null && $model->parentCategory->alias == $a) {
                 // приложение -> материал по ID
                 return $this->renderItem($model);
             }
         }
         // категория дефолтного приложения -> материал
     }
     throw new NotFoundHttpException('The requested page does not exist.');
 }
예제 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Categories::find();
     $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, 'type' => $this->type, 'parent_id' => $this->parent_id, 'app_id' => $this->app_id, 'sort' => $this->sort, 'state' => $this->state, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'params', $this->params]);
     return $dataProvider;
 }
예제 #3
0
파일: form.php 프로젝트: worstinme/yii2-zoo
		<?php 
    echo Html::activeDropDownList($model, $attribute . '[0]', $parent_categories, ['id' => 'item-' . $attribute, 'prompt' => 'выбрать из списка', 'class' => 'uk-width-1-1 category-select']);
    ?>
		<?php 
    if (count($model->category)) {
        ?>
		<?php 
        $i = 0;
        foreach ($model->category as $key => $category_id) {
            ?>
			<?php 
            if ($category_id > 0) {
                ?>
		
				<?php 
                $related_cats = ArrayHelper::map(\worstinme\zoo\models\Categories::find()->where(['parent_id' => $category_id])->all(), 'id', 'name');
                ?>
				<?php 
                if (count($related_cats)) {
                    $i++;
                    ?>
				<div class="related-category-select uk-margin-top">
					<?php 
                    echo Html::activeDropDownList($model, $attribute . '[' . ($key + 1) . ']', $related_cats, ['prompt' => 'выбрать из списка', 'class' => 'uk-width-1-1  category-select']);
                    ?>
	
				<?php 
                }
                ?>
			<?php 
            }