<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## 知識點: 1、工作思路 2、前臺鏈接修改 3、鏈接地址靜態化 4、后臺靜態生成模板搭建 5、全站靜態化生成 6、封裝生成靜態化方法 7、內容頁生成 8、列表頁生成 [TOC] ## 一、工作思路 ### 1、相關文章 ThinkPHP5.0---靜態方法 https://www.cnblogs.com/qq597585136/p/7228678.html ThinkPHP 的頁面靜態化功能的實現(一) https://blog.csdn.net/sinat_35861727/article/details/54971392 ThinkPHP 的頁面靜態化功能的實現(二) https://blog.csdn.net/sinat_35861727/article/details/54971805 ThinkPHP 的頁面靜態化功能的實現(三) https://blog.csdn.net/sinat_35861727/article/details/54972916 thnkphp5行為擴展html靜態緩存源碼下載 http://www.yunshare.net/Article/12/7.html 當后臺開啟靜態(即判斷 static==1 ),那么前臺控制器就要控制鏈接地址為靜態鏈接,否則就是動態鏈接 具體實現,就是在前臺初始化操作中判斷 ### 2、控制器設置 ~~~ public function _initialize() { // 判斷緩存中是否有靜態化配置項 if(!cache('static')){ $static = DB::name('config')->where('varname','static')->value('value'); cache('static',$static); } $this->assign('static',cache('static')); } ~~~ ### 3、模板判斷 內容動態鏈接 http://www.demo.cn/index/index/show/id/87/catid/28.html 內容靜態鏈接 http://www.demo.cn/show_x_y.shtml 模板中判斷是否開啟靜態 ~~~ {if condition='$static'}../show_{$vo.catid}_{$vo.id}.shtml{else/}{:url('show',['id'=>$vo.id,'catid'=>$vo.catid])}{/if} ~~~ ## 二、前臺鏈接修改 ### 1、分類鏈接 分類動態鏈接 http://www.demo.cn/index/index/fenlei/id/28.html?page=1 分類靜態鏈接 http://www.demo.cn/list_x_y.shtml 備注:x-分類id,y-分頁 ### 2、內容鏈接 內容動態鏈接 http://www.demo.cn/index/index/show/id/87/catid/28.html 內容靜態鏈接 http://www.demo.cn/show_x_y.shtml 備注:x-分類id,y-內容id ## 三、鏈接地址靜態化 ### (一)后臺設置靜態開關 ~~~ public function _initialize() { // 判斷緩存中是否有靜態化配置項 if(!cache('static')){ $static = DB::name('config')->where('varname','static')->value('value'); cache('static',$static); } $this->assign('static',cache('static')); } ~~~ ### (二)前臺判斷 ~~~ http://www/index/index/category/id/28.html?page=1 http://www/category_x_y.shtml [x-分類id,y-分頁] {if condition='$static'}../category_{$vo.id}_1.shtml{else/}{:url('category',['id'=>$vo.id])}{/if} http://www/index/index/info/id/87/catid/28.html http://www/show_x_y.shtml [x-分類id,y-內容id] {if condition='$static'}../show_{$vo.catid}_{$vo.id}.shtml{else/}{:url('info',['id'=>$vo.id,'catid'=>$vo.catid])}{/if} 首頁文章 <a href="{if condition='$static'}../show_{$vo.catid}_{$vo.id}.shtml{else/}{:url('info',['id'=>$vo.id,'catid'=>$vo.catid])}{/if}"> <img src="__UPLOADS__/{$vo.thumb}" alt="{$vo.title}"> </a> 首頁分類 <a href="{:url('category',['id'=>$vo.catid])}">{$vo.catid|getCatInfoById=catname}</a> 列表頁文章 <a href="{if condition='$static'}../../../../show_{$vo.catid}_{$vo.id}.shtml{else/}{:url('info',['id'=>$vo.id,'catid'=>$vo.catid])}{/if}" rel="bookmark"> {$vo.title} </a> 列表頁分類 <a href="{if condition='$static'}../../../../list_{$vo.catid}_1.shtml{else/}{:url('category',['id'=>$vo.catid])}{/if}"> {$vo.catid|getCatInfoById=catname} </a> 內容頁文章 <a href="{if condition='$static'}http://{$Think.server.HTTP_HOST}/show_{$vo.catid}_{$vo.id}.shtml{else/}{:url('info',['id'=>$vo.id,'catid'=>$vo.catid])}{/if}"> <img src="__UPLOADS__/{$vo.thumb}" alt="{$vo.title}"> </a> 內容頁分類 <a href="{if condition='$static'}http://{$Think.server.HTTP_HOST}/list_{$vo.catid}_1.shtml{else/}{:url('category',['id'=>$vo.catid])}{/if}"> {$vo.catid|getCatInfoById=catname} </a> 菜單項 <ul class="sub-menu"> {volist name="vo.son" id="voson"} <li> <a href="{if condition='$static'}http://{$Think.server.HTTP_HOST}/list_{$voson.id}_1.shtml{else/}{:url('category',['id'=>$voson.id])}{/if}"> {$voson.catname} </a> </li> {/volist} </ul> ~~~ ## 四、后臺靜態生成模板搭建 ### (一)新建“發布管理”菜單 1、菜單>發布管理>靜態生成 2、新建控制器Staticpage和模板“staticpage/index” 3、完善控制器和模板 ## 五、全站靜態化生成 主要目標:生成首頁 ~~~ public function index(){ $url = 'http://www/index.php'; //動態頁面地址 $fn = ROOT_PATH . 'public/index.html'; //生成文件名 $content = file_get_contents($url); $fs = fopen($fn, 'w'); fwrite($fs, $content); return view(); } ~~~ ## 六、封裝生成靜態化方法 ~~~ protected $domain = ''; public function _initialize(){ $this->domain = "http://" . input('server.HTTP_HOST'); // 獲取域名 } public function createHtml($visitUrl, $createName){ $url = $this->domain . '/index.php/index/index/' . $visitUrl; //動態頁面地址 $fn = ROOT_PATH . 'public/' . $createName; //生成文件名 $content = file_get_contents($url); $fs = fopen($fn, 'w'); fwrite($fs, $content); } ~~~ ## 七、內容頁生成 ~~~ public function createInfo(){ if(request()->isPost()){ // 獲取模型中所有的tablename $models = Db::name('models')->column('tablename'); foreach ($models as $name) { $lists = Db::name($name)->field('id,catid')->select(); if(count($lists)){ foreach ($lists as $value) { $visitUrl = 'info/id/'.$value['id'].'/catid/'.$value['catid']; $createName = 'a/show_'.$value['catid'].'_'.$value['id'].'.shtml'; $this->createHtml($visitUrl, $createName); } } } return success('內容頁生成成功!'); } } ~~~ ## 八、列表頁生成 ### (一)思路分析 頂層分類沒有文章的 每個分類ID對應一個模型ID 每個模型對應一張數據表 查詢數據表分頁操作 兩個參數:一個是分類ID;一個是頁數 頁數:總共記錄數;每頁顯示多少條 配置文件:\application\index\config.php 算法:$num = ceil($count/5); //進一取整函數 ceil() 函數向上舍入為最接近的整數。 返回不小于 x 的下一個整數,x 如果有小數部分則進一位。 ceil() 返回的類型仍然是 float,因為 float 值的范圍通常比 integer 要大。 功 能:返回大于或者等于指定表達式的最小整數 ### (二)分頁配置 ~~~ <?php return [ 'paginate' => [ 'type' => 'layui', 'var_page' => 'page', 'list_rows' => '5', 'newstyle' => true, ], ]; ~~~ ### (三)后臺操作 #### 1、生成分類 ~~~ public function createCategory(){ if(request()->isPost()){ $ids = Db::name('category')->where('modelid','neq',0)->column('id'); foreach ($ids as $id) { // 根據分類ID獲取相應數據表名 $tablename = getModInfoById($id, 'tablename'); // 獲取數據表中相應分類記錄數,再計算出頁數 $count = Db::name($tablename)->where('catid', $id)->count(); if($count){ $num = ceil($count/5); //進一取整函數 for($i = 1; $i<$num+1; $i++){ $visitUrl = 'category/id/'.$id.'?page='.$i; $createName = 'a/list_'.$id.'_'.$i.'.shtml'; $this->createHtml($visitUrl, $createName, true, $id); } } } return success('分類頁生成成功!'); } } ~~~ #### 2、根據分類ID獲取相應模型信息 ~~~ function getModInfoById($id=0, $field=''){ //模型ID、 $modelId = getCatInfoById($id, 'modelid'); if($field == ''){ //獲取單條數據 return Db::name('models')->where('id',$modelId)->find(); }else{ //獲取某個字段 return Db::name('models')->where('id',$modelId)->value($field); } } ~~~ #### 3、創建靜態頁 ~~~ public function createHtml($visitUrl, $createName){ $url = $this->domain . '/index.php/index/index/' . $visitUrl; //動態頁面地址 $fn = ROOT_PATH . 'public/' . $createName; //生成文件名 $content = file_get_contents($url); $fs = fopen($fn, 'w'); fwrite($fs, $content); } ~~~ #### 4、創建靜態頁升級 動態支持列表頁傳遞頁碼參數 ~~~ public function createHtml($visitUrl, $createName, $hasPage = false, $catid = 0){ $url = $this->domain . '/index.php/index/index/' . $visitUrl; //動態頁面地址 $fn = ROOT_PATH . 'public/' . $createName; //生成文件名 $content = file_get_contents($url); if($hasPage){ $content = preg_replace("(<a[^>]*page[=|/](\d+).+?>(.+?)<\/a>)", "<a href='category_".$catid."_$1.shtml'>$2</a>", $content); } $fs = fopen($fn, 'w'); fwrite($fs, $content); } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看