public function actionUpdate($id) { $model = $this->findModel($id); if ($model->load($_POST)) { $parentIds = Channel::getParentIds($model['parent_id']); if (in_array($model['id'], $parentIds)) { LuLu::setErrorMessage('不能设置父节点为当前节点的子节点'); return $this->redirect(['update', 'id' => $id]); } $model->save(); CacheUtility::createChannelCache(); return $this->redirect(['index']); } else { $locals = []; $locals['model'] = $model; $locals['tableList'] = CommonUtility::getTables(); $locals['channelTpls'] = $this->getTpl('channel_'); $locals['listTpls'] = $this->getTpl('list_'); $locals['detailTpls'] = $this->getTpl('detail_'); return $this->render('update', $locals); } }
public static function createChannelCache() { self::createCacheFile(); $content = '<?php' . self::$newLine; $dataList = Channel::_getChannelArrayTree(0, 0); foreach ($dataList as $row) { $id = $row['id']; $parentIds = Channel::getParentIds($id); $childrenIds = Channel::getChildrenIds($id); $leafIds = Channel::getLeafIds($id); $content .= '$cachedChannels[\'' . $row['id'] . '\']=[' . self::$newLine; $content .= self::getCacheItem('id', $row, 'int'); $content .= self::getCacheItem('parent_id', $row, 'int'); $content .= self::getCacheItemValue('parent_ids', implode(',', $parentIds)); $content .= self::getCacheItemValue('child_ids', implode(',', $childrenIds)); $content .= self::getCacheItemValue('leaf_ids', implode(',', $leafIds)); $content .= self::getCacheItem('name', $row); $content .= self::getCacheItem('name_alias', $row); $content .= self::getCacheItem('name_url', $row); $content .= self::getCacheItem('redirect_url', $row); $content .= self::getCacheItem('level', $row, 'int'); $content .= self::getCacheItem('is_leaf', $row, 'bool'); $content .= self::getCacheItem('is_nav', $row, 'bool'); $content .= self::getCacheItem('sort_num', $row, 'int'); $content .= self::getCacheItem('table', $row); $content .= self::getCacheItem('channel_tpl', $row); $content .= self::getCacheItem('list_tpl', $row); $content .= self::getCacheItem('detail_tpl', $row); $content .= self::getCacheItem('page_size', $row, 'int'); $content .= self::getCacheItem('seo_title', $row); $content .= self::getCacheItem('seo_keywords', $row); $content .= self::getCacheItem('seo_description', $row); $content .= "];" . self::$newLine; } self::writeFile('cachedChannels.php', $content); }