Beispiel #1
0
 /**
  * Finds the model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Category::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #2
0
 /**
  * Renders the widget.
  */
 public function run()
 {
     $categories = Html::getAttributeValue($this->model, $this->attribute);
     $model = new Category();
     $tree = Category::findOne(['module' => $this->model->moduleName, $model->leftAttribute => 1]);
     if ($tree) {
         $tree = $tree->buildTreeHtml([], [], ['actions' => '<div class="btn-group pull-right">
                 <input type="checkbox" {check} class="choseCategories" name="choseCategories[]" value="{_id}">
             </div>'], $categories);
     }
     echo $tree;
 }
Beispiel #3
0
 public function actionIndex($id, $module = null)
 {
     if ($module != 'faq') {
         $query = Question::find();
     } else {
         $query = \app\modules\faq\models\Faq::find();
     }
     $query->orderBy('_id ASC');
     $query->where(['category' => $id]);
     Yii::$app->view->title = Category::findOne($id)->name;
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20]]);
     return $this->render('index', ['model' => $dataProvider]);
 }
Beispiel #4
0
 public function actionIndex($module, $id)
 {
     $modelClassName = ucfirst($module);
     $modelClass = "\\app\\modules\\{$module}\\models\\{$modelClassName}";
     if (!class_exists($modelClass)) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     if (($category = Category::findOne($id)) == NULL) {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
     $obj = Yii::createObject($modelClass);
     $query = $obj::find()->where(['status' => '1', 'category' => $category->primaryKey]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 20], 'sort' => ['defaultOrder' => ['sort' => SORT_DESC, 'create_time' => SORT_DESC]]]);
     return $this->render('index', ['category' => $category, 'dataProvider' => $dataProvider]);
 }
Beispiel #5
0
 public function run()
 {
     Yii::$app->cache->flush();
     $cacheKey = $this->module . '_Tree_' . $this->module . '_' . $this->category;
     $cache = Yii::$app->cache->get($cacheKey);
     if (!$cache) {
         $model = new Category();
         $where = [$model->leftAttribute => 1];
         if (!empty($this->module)) {
             $where['module'] = $this->module;
         }
         if (!empty($this->category)) {
             $where['_id'] = $this->category;
         }
         $models = Category::findOne($where);
         $models = $models->leaves()->all();
         Yii::$app->cache->set($cacheKey, $models);
     } else {
         $models = $cache;
     }
     if (!empty($models)) {
         return $this->render($this->view, ['models' => $models, 'title' => $this->title, 'module' => $this->module, 'category' => $this->category]);
     }
 }
Beispiel #6
0
 protected function findModel($id)
 {
     if (is_array($id)) {
         $model = Category::findAll($id);
     } else {
         $model = Category::findOne($id);
     }
     if ($model !== null) {
         return $model;
     } else {
         throw new HttpException(404);
     }
 }
Beispiel #7
0
 public function actionDeletecategory()
 {
     $id = Yii::$app->request->post('id', NULL);
     $category = Category::findOne(['_id' => $id]);
     $category->deleteWithChildren();
     echo json_encode(1);
 }