tp系列----------從入門到精通

六:thinkphp隱藏index.php及打開默認index.html

1、隱藏index.php

a. 引入.htacess文件

<IfModule mod_rewrite.c>
  Options +FollowSymlinks
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
</IfModule>
<IFModule mod_headers.c>
Header always append X-Frame-Options SAMEORIGIN
</IFModule>
RewriteCond %{QUERY_STRING} \=PHP[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} [NC]
RewriteRule .* - [F]

# disable directory browsing
Options All -Indexes

b.修改配置文件,引入重寫

LoadModule rewrite_module modules/mod_rewrite.so

2、 開始打開index.html

    修改配置文件httpd.conf,把index.html放前面。如下:

<IfModule dir_module>
    DirectoryIndex index.html index.php index.htm l.php
</IfModule>

詳細講解視頻: https://edu.csdn.net/course/play/25405/321160

九:tp接口數據實時監控公共類函數

寫了一個公共類函數,可以放到接口中,不影響接口程序運行,能打印接口中代碼每一行的數據。

在application/common/model下建一個公共類LoggerModel.class.php

代碼如下:

namespace Common\Model;
use Think\Model;
/**
 */
class LoggerModel {
	private static $path = LOG_PATH; 
    public static function debug(){
        self::output('debug',func_get_args());
    }
    public static function output($type='debug'){
    	$dir = self::$path.date('Y/m').'/'.$type.'/';
		if( !is_dir($dir) ){
			mkdir($dir,0777,true);
		}
		$file = $dir .'/'. date('Ymd').'.log';
		$fp = fopen($file,'a+');
		if( $fp ){
			$backtrace = debug_backtrace();
			$arr = array(
					'['.date('Y-m-d H:i:s').']',
					'['.GetRemoteIp().']',
					'['.$backtrace[1]['file'].']',
					'['.$backtrace[1]['line'].']',
			);
			try{
				$param = func_get_args()[1];
				if(sizeof($param) == 1){
					if(is_string($param[0])){
						$arr[] = ':【'.$param[0].'】';
					}else{
						$arr[] = ':【'.var_export($param[0],true).'】';
				    }
				}else{
					$str = $param[0];
					for ($i=1; $i < sizeof($param); $i++) { 
					   $str = preg_replace ('/#/',var_export($param[$i],true), $str,1);
				    }
				    $arr[] = ':【'.$str.'】';
				}
			}catch(Exception $e){
	    		$arr[] = ':【Log error!Exception = '.var_export($e,true).'】';
	   		}  
			fwrite($fp, implode('',$arr)."\n");
			fclose($fp);
		}
		return;
    }
}

在接口中調用如下:

當接口被調用時,會在日誌中打印如下:

注:這樣,就能監控接口中任意一行代碼打印的數據。

詳細操作視頻:https://edu.csdn.net/course/play/25405/322110

十:10tp修改默認接口及視圖的底層實現

1、修改默認控制器方法

在Application\Common\Conf\config.php中,加入如下一行:

'DEFAULT_ACTION'=>'sendDynamic',

注意:此時,默認控制方法就改成了sendDynamic,如果調用其他接口,不寫方法時,就會找這個方法(sendDynamic),如果沒找到將報錯。

2、控制器定位視圖

定位

$this->display();

注:display不傳參,定位到/view/abc/ab.html,如果display傳參,如下:

$this->display('hello');//將會定位到/view/abc/hello.html

傳值:$this->assign('_data',$data);

詳細講解視頻:待發布

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章