コード例 #1
0
ファイル: CacheUtility.php プロジェクト: hucongyang/lulucms2
 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);
 }
コード例 #2
0
ファイル: DictSearch.php プロジェクト: dw250100785/lulucms
 public function search($params)
 {
     $query = Dict::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'parent_id' => $this->parent_id, 'sort_num' => $this->sort_num]);
     $query->andFilterWhere(['like', 'category_key', $this->category_key])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'value', $this->value])->andFilterWhere(['like', 'datatype', $this->datatype]);
     return $dataProvider;
 }
コード例 #3
0
ファイル: Dict.php プロジェクト: dw250100785/lulucms
 public static function _getDictArrayTree($categoryId, $parentId = 0, $level = 0)
 {
     $ret = [];
     $dataList = Dict::findAll(['category_id' => $categoryId, 'parent_id' => $parentId], 'sort_num asc');
     if ($dataList == null || empty($dataList)) {
         return $ret;
     }
     foreach ($dataList as $key => $value) {
         $value->level = $level;
         $ret[] = $value;
         $temp = self::_getDictArrayTree($categoryId, $value['id'], $level + 1);
         $ret = array_merge($ret, $temp);
     }
     return $ret;
 }
コード例 #4
0
 public function actionDelete($id)
 {
     $this->findModel($id)->delete();
     Dict::deleteAll(['category_id' => $id]);
     return $this->redirect(['index']);
 }
コード例 #5
0
 /**
  * Finds the Dict model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Dict the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     $id = intval($id);
     if ($id === 0) {
         $model = new Dict();
         $model->id = 0;
         $model->name = '根字典';
         return $model;
     }
     if (($model = Dict::findOne($id)) !== null) {
         return $model;
     } else {
         //throw new NotFoundHttpException('The requested page does not exist.');
     }
 }