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);

详细讲解视频:待发布

 

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