thinkphp路径去除index.php等小技巧
thinkphp路径去除index.php
改apache 的配置文件:
1)打开:mod_rewrite.so 模块加载
2)AllowOverride None,把None改为All
改nginx:https://www.kancloud.cn/manual/thinkphp5/177576
location / { // …..省略部分代码
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=/$1 last;
break;
}
}
或者二级目录
location /youdomain/ {
if (!-e $request_filename){
rewrite ^/youdomain/(.*)$ /youdomain/index.php?s=/$1 last;
}
}
3)tp5获取时间相关
获取当前时间:
$now = time();
时间戳转换正常时间格式:
date('Y-m-d H:i:s',time());
日期转换为时间戳:
$date="2020-03-16 18:56:21";
strtotime($date);
实际用法如下:
->whereTime('时间字段','year')//查询本年
->whereTime('时间字段','month')//查询本月
->whereTime('时间字段','week')//查询本周
->whereTime('时间字段','last year')//查询去年
->whereTime('时间字段','last month')//查询上个月月
->whereTime('时间字段','last week')//查询上周
->whereTime('时间字段','between',['2020-1-1','2020-1-10'])
// 查询一个小时内的博客
Db::table('blog')->whereTime('create_time','-1 hours')->select()
// 之间的时间
$startDay = date('Y-m-d', strtotime('-6 days'));
$endDay = date('Y-m-d', strtotime('+1 days'));
Db::name('orders')
->field('createTime,orderId')
->whereBetweenTime('createTime', $startDay, $endDay)
->where('shopId', $shopId)
->where('orderStatus', '>', 2)
->select();
时间戳:https://tool.lu/timestamp/
本周一的时间戳
strtotime('this week Monday',time());
strtotime('last week Monday');//上个星期的星期一
以下是年,月,周,天,时,分秒的用法
date("Y-m-d H:i:s", strtotime(" +2 year"));
date("Y-m-d H:i:s", strtotime(" +2 month"));
date("Y-m-d H:i:s", strtotime(" +2 week"));
date("Y-m-d H:i:s", strtotime(" +2 day"));
4) 参数过滤
在ThinkPHP5中提供了许多数据输入过滤方法,例如
//强制转换为Email格式
$this->request->post('email','',FILTER_VALIDATE_EMAIL);
$this->request->post('email','','email');
//强制转换为数字
$this->request->post('id/d','0');
常用的修饰符如下
修饰符 作用
s 强制转换为字符串类型
d 强制转换为整型类型
b 强制转换为布尔类型
a 强制转换为数组类型
f 强制转换为浮点类型
5) api需要权限,加token传过去。
6) php数组长度:count($arrData);
7) string转int:(int)$s