ThinkPHPtp5+小程序开发笔记(一)tp5路由/传参/验证AOP编程思想--面向切面编程 tp5路由: (设置了路由后pathinfo失效) Route::rule('路由表达式','路由地址','请求类型','路由参数(数组)','变量规则(数组)'); 请求类型:get post delete put any(默认所有) use think\Route; Route::rule('test','api/Test作者王明昌发布时间2018-04-06最后更新2018-04-06文章目录tp5路由:获取参数1.2.助手函数3.依赖注入验证 AOP编程思想--面向切面编程 tp5路由: (设置了路由后pathinfo失效) Route::rule('路由表达式','路由地址','请求类型','路由参数(数组)','变量规则(数组)'); 请求类型:get post delete put any(默认所有) 复制use think\Route; Route::rule('test','api/Test/index','GET'); Route::rule('test','api/Test/index','GET | POST'); 路由中传递参数 get方式 复制Route::rule('test/:id','api/Test/index','GET');复制public function index($id,$name) { echo "id=".$id."name=".$name; } 访问方式:http://localhost/xcx_shop/public/index.php/test/11?name=xx post方式 复制Route::post('test/:id','index/test/index'); 获取参数1.复制use think\Request; param不区分参数来源 获取单个传过来的参数 $id = Request::instance()->param('id'); 获取所有传过来的参数 $all = Request::instance()->param(); 获取get方式传过来的参数 $all = Request::instance()->get(); 获取路径中传过来的参数 $all = Request::instance()->route(); 获取post方式传过来的参数 $all = Request::instance()->post(); ....2.助手函数复制input('param.');3.依赖注入复制use think\Request; public function test(Request $request) { $all = $request->param(); } //$request 不需要关注从哪里来的 验证 1.独立验证 复制$validate = new Validate([ 'pwd' => 'require', 'new_pwd' => 'require', 'confirm_pwd' => 'require|confirm:new_pwd' ],[ 'pwd.require' => '请输入原始密码', 'new_pwd.require' => '请输入新密码', 'confirm_pwd.require' => '请重复新密码', 'confirm_pwd.confirm' => '确认密码与新密码不一致' ] ); if (!$validate->check($data)) { return ['valid'=> 0,'msg'=>$validate->getError()]; } //原始密码是否正确 $userInfo = $this->where('pwd',$data['pwd'])->where('id',session('admin_id'))->find(); if(!$userInfo){ return ['valid'=>0, 'msg'=>'原始密码不正确']; } //修改密码 // save方法第二个参数为更新条件 $res = $this->save([ 'pwd' =>$data['new_pwd'], ],[$this->pk => session('admin_id')]); if($res){ return ['valid'=>1, 'msg'=>'密码修改成功']; }else{ return ['valid'=>0, 'msg'=>'密码修改失败']; } 2.验证器 新建TestValideta.php 复制 'require', 'new_pwd' => 'require', 'confirm_pwd' => 'require|confirm:new_pwd' ]; protected function isInt($value,$rule='',$data,$field='') { if(is_number($value) && is_int($value +0) && ($value +0)>0){ return true; }else{ return $field."必须是正整数"; } } } 使用: $validate = new TestValidate(); $result = $validate ->batch()->check($data); 3.自定义验证规则(如上) 复制protected function isInt($value,$rule='',$data,$field='') { if(is_number($value) && is_int($value +0) && ($value +0)>0){ return true; }else{ return $field."必须是正整数"; } }
2018-05-29执行ajax成功后进行页面的刷新location.reload(true); window.location.reload(); $("#train").on("click",function(){ var id = $("#id_
2017-02-11Wordpress文章分类目录不能正常调用,解决办法如图所示,分类目录不能正常调用 点击了php开发目录,而打开的是建站教程这一栏 解决方法:点击设置----固定链接----分类目录前缀----输入%category% 保存,之后刷新一下就解决了
2017-11-18PHP函数-数学函数abs 格式 描述 输入 输出 abs() 绝对值 整形/浮点型/字符串/进制数 与输入相对应 实例: $a = -12;//12 $a = -112.02;//11.02 $a = "-123.2"
2018-04-10赢政天下Adobe CC 2018大师版安装包合集 含28个安装包嬴政天下的这个安装包非常好用,而且这些安装包都是免登录授权的,也就是说破解版的。 小编自己用的就是嬴政天下的安装包,附件包含很多个安装包,朋友们可以挑选自己需要的下载。 还有BT链接,朋友们可以复制使