コード例 #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);
     }
 }
コード例 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CatalogCategories::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'disabled' => $this->disabled, 'parent_id' => $this->parent_id]);
     $query->andFilterWhere(['like', 'code', $this->code])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug]);
     return $dataProvider;
 }
コード例 #3
0
ファイル: Catalog.php プロジェクト: chameleon82/yiindo
 /**
  * @inheritdoc
  */
 public function getCategory()
 {
     return $this->hasOne(CatalogCategories::className(), ['id' => 'category_id']);
 }
コード例 #4
0
ファイル: _nav.php プロジェクト: chameleon82/yiindo
<?php

/**
 * Created by JetBrains PhpStorm.
 * User: Александр
 * Date: 27.05.15
 * Time: 23:57
 * To change this template use File | Settings | File Templates.
 */
$this->beginBlock('catalogNav');
$ids = [];
$id = $catalog_category ? $catalog_category->id : null;
if ($catalog_category->route) {
    foreach ($catalog_category->route as $r) {
        $ids[] = $r->id;
    }
}
$tree = \app\helpers\ArrayHelper::tree(\yii\helpers\ArrayHelper::toArray(\app\modules\catalog\models\CatalogCategories::find()->orderBy('ordering')->all()), 'id', 'parent_id', 'childs');
echo frontend\widgets\Tree::widget(['data' => $tree, 'childAttribute' => 'childs', 'groupTag' => 'div', 'groupOptions' => function ($data, $level, $parent) use($ids) {
    return $level === 0 ? ['class' => 'list-group'] : (in_array($parent, $ids) ? ['class' => 'submenu panel-collapse collapse in'] : ['class' => 'submenu panel-collapse collapse']);
}, 'elementTag' => 'a', 'elementOptions' => function ($data, $level, $parent, $widgetId) use($id) {
    return ['href' => count($data['childs']) ? '#' . $widgetId . '-navi-' . $data['id'] : \yii\helpers\Url::to(['categories/view', 'id' => $data['id']]), 'data-toggle' => count($data['childs']) ? 'collapse' : '', 'class' => 'list-group-item' . ($id == $data['id'] ? ' active' : '')];
}, 'value' => function ($data, $level) {
    return ($level == 0 ? mb_strtoupper($data['title'], 'UTF-8') : $data['title']) . (count($data['childs']) != 0 ? ' ' . \yii\helpers\Html::tag('b', '', ['class' => 'caret']) : '');
}]);
$this->endBlock();
コード例 #5
0
 /**
  * Finds the CatalogCategories model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CatalogCategories the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CatalogCategories::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }