-
如何觸發(fā)系統(tǒng)生成純靜態(tài)化頁面的方法: 1、頁面添加緩存時間 2、手動觸發(fā)方式 3、crontab定時掃描程序查看全部
-
index.php <?php //1.連接數(shù)據(jù)庫、然后從數(shù)據(jù)庫里面獲取數(shù)據(jù) //db.php對連接數(shù)據(jù)庫進行了封裝(Db類采用了單例模式,如果要使用必須要經(jīng)過getInstance這個方法,然后再調(diào)用connect這個方法,connect最終返回一個對數(shù)據(jù)庫的連接資源句柄) require_once('./db.php'); $connect = Db::getInstance()->connect(); $sql = "select *from news where `category_id`=1 and `status`=1 order by id desc limit 5"; //$sql = "select *from article limit 4"; $result = mysql_query($sql,$connect); $news = array(); while($row = mysql_fetch_array($result)){ $news[] = $row; } //2.把獲取到的數(shù)據(jù)填充到模板里面 //引入模板文件 ob_start();//開啟緩沖區(qū)(echo輸出語句或模板頁面等都會先經(jīng)過緩沖區(qū)) require_once('./templates/temp.php'); //3.需要把動態(tài)的頁面轉(zhuǎn)化為靜態(tài)頁面,生成純靜態(tài)文件 if(file_put_contents('index.shtml',ob_get_clean())){ echo "success"; }else{ echo "error"; } PHP實現(xiàn)頁面靜態(tài)化有一下步驟: 1:A.php請求數(shù)據(jù)庫數(shù)據(jù):通過mysql或者mysqli或者PDO擴展 2:在B.html中輸出A.php請求的數(shù)據(jù)庫數(shù)據(jù):一般是將將在數(shù)據(jù)庫中取出的數(shù)組形式的數(shù)據(jù)賦予新的數(shù)組,并且輸出 3:在A.php中包含B.html文件:直接通過require_once()函數(shù)或者inclde_once() 4:開啟數(shù)據(jù)緩存ob_start()=>獲取獲取緩存內(nèi)容并且將數(shù)據(jù)生成在靜態(tài)文件中file_put_contents('index.shtml',ob_get_clean());查看全部
-
singwa.php 用foreach循環(huán)把數(shù)據(jù)填充到這個模板中。 <ul> <?php foreach($news as $k=>$v){?> <li><a href="/" target="_blank"><?php echo $v['title'] ?></a></li> <?php }?> </ul>查看全部
-
jQuery封裝的ajax方法使用更方便查看全部
-
ob_start();ob_get_contents();ob_clean();ob_get_clean();查看全部
-
如何觸發(fā)系統(tǒng)生成純靜態(tài)化頁面查看全部
-
ob函數(shù)查看全部
-
apache RewriteEngine on RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteRule ^/detail/([0-9]*).html$ /detail.php?id=$1查看全部
-
nginx rewrite^/post/([0-9]*).shtml $ /detail.php?id=$1查看全部
-
純靜態(tài)化原理查看全部
-
ob_get_contents — 返回輸出緩沖區(qū)的內(nèi)容; php.ini 中的配置項:output_buffering=on 需要先開起,才能調(diào)用ob_get_contents()函數(shù)。但是,如果不開啟output_buffering時,當在頭文件中調(diào)用函數(shù)ob_start()函數(shù)時,ob_get_contents()也能使用。查看全部
-
局部動態(tài)化查看全部
-
PHP如何實現(xiàn)頁面靜態(tài)化查看全部
-
純靜態(tài)化案例之步驟解析 當在瀏覽器請求index.php這個文件,這個文件的目的就是需要在網(wǎng)站的根目錄下面去生成一個index.shtml靜態(tài)文件。這個靜態(tài)文件生成好之后是提供給用戶來訪問的,它的結(jié)構(gòu)是用到templates下的singwa.php的結(jié)構(gòu),只不過它里面的數(shù)據(jù)不一樣。 步驟解析: 1、連接數(shù)據(jù)庫、然后從數(shù)據(jù)庫里面獲取數(shù)據(jù) 2、把獲取到的數(shù)據(jù)填充到模板文件里面 3、需要把動態(tài)的頁面轉(zhuǎn)化為靜態(tài)頁面,生成純靜態(tài)化文件查看全部
-
1.用到Php內(nèi)置的文件操作函數(shù)(file_put_contents()) 2.使用Php緩沖區(qū)機制(ob_start, ob_get_contents, ob_clean, ob_get_clean)查看全部
舉報
0/150
提交
取消