Exemplo n.º 1
0
 public static function createDictCache()
 {
     self::createCacheFile();
     $content = '<?php' . self::$newLine;
     $categories = DictCategory::findAll();
     foreach ($categories as $category) {
         $content .= '$cachedDicts[\'' . $category['id'] . '\']=[' . self::$newLine;
         $dicts = Dict::_getDictArrayTree($category['id'], 0, 0);
         foreach ($dicts as $row) {
             $id = $row['id'];
             $childrenIds = Dict::getChildrenIds($id);
             $content .= '	\'' . $id . '\'=>[' . self::$newLine;
             $content .= '	' . self::getCacheItem('id', $row, 'int');
             $content .= '	' . self::getCacheItem('parent_id', $row, 'int');
             $content .= '	' . self::getCacheItemValue('child_ids', implode(',', $childrenIds));
             $content .= '	' . self::getCacheItem('category_id', $row);
             $content .= '	' . self::getCacheItem('name', $row);
             $content .= '	' . self::getCacheItem('value', $row);
             $content .= '	' . self::getCacheItem('level', $row, 'int');
             $content .= '	' . self::getCacheItem('sort_num', $row, 'int');
             $content .= "\t]," . self::$newLine;
         }
         $content .= "];" . self::$newLine;
     }
     self::writeFile('cachedDicts.php', $content);
 }
Exemplo n.º 2
0
 public function checkExist()
 {
     if ($this->isNewRecord || $this->id != $this->oldAttributes['id']) {
         $ret = DictCategory::findOne($this->id);
         return $ret !== null;
     }
     return false;
 }
 protected function findModel($id)
 {
     if (($model = DictCategory::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 4
0
 public function search($params)
 {
     $query = DictCategory::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['is_sys' => $this->is_sys]);
     $query->andFilterWhere(['like', 'key', $this->key])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Exemplo n.º 5
0
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $pid = $model->parent_id;
     $catid = $model->category_id;
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         CacheUtility::createDictCache();
         return $this->redirect(['index', 'pid' => $pid, 'catid' => $catid]);
     } else {
         $locals = [];
         $locals['model'] = $model;
         $locals['parent'] = $this->findModel($pid);
         $locals['parents'] = Dict::getParents($pid);
         $locals['category'] = DictCategory::findOne($catid);
         return $this->render('update', $locals);
     }
 }