TP5
Thinkphp5判断是否使用手机访问,TP5如何区分PC端还是手机端访问?
判断用户是否使用手机端访问,这个是我们做web研发时经常遇到的一个功能点。 一个很简单的功能点,解决方案也有很多种,比如使用原生PHP通过分析UA来判断。 但如果你的后端用的是ThinkPHP5框架的话,解决这个功能点就更简单了,因为TP5的源码中已经封装好了,我们可以直接使用。 1 2 3 4 5 ......
tp5.1 多条件搜索时搜索null和不为null
搜索null时 $map = []; $map[] = ['a.admin_id|a.department','null','']; 搜索不为null 时 $map = []; $map[] = ['a.admin_id|a.department','not null','']; ......
TP5查询数据列表追加字段
$userList = Db::name('user')->where('status',1)->select();$userList = array_map(function($item){ $item['newField'] = 'newValue'; // 在结果数组中追加新字段和值 retu ......
tp5 update方法更新数据
thinkphp5的update方法: 返回影响数据的条数,没修改任何数据返回0 当要更新的数据和已存在数据库的数据一样时,返回的结果为0 修改失败返回false 所以在判断更新是否成功,要用 的条件进行判断 0 和 false的情况 public function update(){ $resul ......
tp5支付宝支付(当面付)
这里只说扫码支付,使用官方的代码,为什么没使用yansongda之类的组件,因为这个封装的太深了问题不好找,所以使用了官方的代码 支付宝支付文档:https://opendocs.alipay.com/open/270/01didh?pathHash=a6ccbe9a 官方代码仓库:https:// ......
TP5环境静态文件报404的解决方案
主要还是站点配置文件,找到vhost下的站点配置文件,代码如下 server { listen 80; server_name www.test.com test.com; index index.html index.htm index.php; #include /usr/local/nginx ......
tp5.1 whereOr查询
public function workList(Request $request,$limit = 10){ if ($request->isAjax()) { $status = $request->param('state'); $map[] = ['state','neq',-1]; if( ......
PHP批量压缩图片,基于TP5,fastadmin
``` * O(∩_∩)O * Date: 2022-7-7 09:34:38 */ namespace app\command; use think\Image; use think\image\Exception; use think\console\{Command, Input, Outpu ......
TP5 验证金额是两位小数 ,1.2, 1, 0.01, 0.1都可以
'amount|价格' => ['require', 'max:128', 'float','>:0', 'regex' => '^(([1-9]{1}\d*)|(0{1}))(\.\d{1,2})?$'], ......