<?php namespace app\index\controller; use think\Request; class Index { /** * 请求信息 * */ public function hello(Request $request,$name = 'World') { echo '获取当前访问的url地址:<br>'; $request = Request::instance(); // 获取当前URL地址 不含域名 echo 'url: ' . $request->url() . '<br/>'; echo '<br>获取请求参数:<br>'; echo '请求方法:' . $request->method() . '<br/>'; echo '资源类型:' . $request->type() . '<br/>'; echo '访问IP:' . $request->ip() . '<br/>'; echo '是否AJax请求:' . var_export($request->isAjax(), true) . '<br/>'; echo '请求参数:'; dump($request->param()); echo '请求参数:仅包含name'; dump($request->only(['name'])); echo '请求参数:排除name'; dump($request->except(['name'])); echo '<br>获取URL信息:<br>'; // 获取当前域名 echo 'domain: ' . $request->domain() . '<br/>'; // 获取当前入口文件 echo 'file: ' . $request->baseFile() . '<br/>'; // 获取当前URL地址 不含域名 echo 'url: ' . $request->url() . '<br/>'; // 获取包含域名的完整URL地址 echo 'url with domain: ' . $request->url(true) . '<br/>'; // 获取当前URL地址 不含QUERY_STRING echo 'url without query: ' . $request->baseUrl() . '<br/>'; // 获取URL访问的ROOT地址 echo 'root:' . $request->root() . '<br/>'; // 获取URL访问的ROOT地址 echo 'root with domain: ' . $request->root(true) . '<br/>'; // 获取URL地址中的PATH_INFO信息 echo 'pathinfo: ' . $request->pathinfo() . '<br/>'; // 获取URL地址中的PATH_INFO信息 不含后缀 echo 'pathinfo: ' . $request->path() . '<br/>'; // 获取URL地址中的后缀信息 echo 'ext: ' . $request->ext() . '<br/>'; echo '<br>获取当前模块/控制器/操作信息:<br>'; echo '模块:'.$request->module(); echo '<br/>控制器:'.$request->controller(); echo '<br/>操作:'.$request->action(); echo '<br>获取路由和调度信息:<br>'; echo '路由信息:'; dump($request->routeInfo()); echo '调度信息:'; dump($request->dispatch()); } /** * 页面跳转 * */ use \traits\controller\Jump; public function index($name='') { if ('thinkphp' == $name) { $this->success('欢迎使用ThinkPHP5.0','aaa'); }else if('onestopweb' == $name){ $this->redirect('http://onestopweb.iteye.com'); }else { $this->error('错误的name','bbb'); } } public function aaa() { return 'Hello,ThinkPHP!'; } public function bbb() { return 'Hello,Guest!'; } }
请求信息的效果文本:
获取当前访问的url地址: url: /index/index/hello/test/ddd.html?name=thinkphp 获取请求参数: 请求方法:GET 资源类型:xml 访问IP:127.0.0.1 是否AJax请求:false 请求参数: array(2) { ["name"] => string(8) "thinkphp" ["test"] => string(3) "ddd" } 请求参数:仅包含name array(1) { ["name"] => string(8) "thinkphp" } 请求参数:排除name array(1) { ["test"] => string(3) "ddd" } 获取URL信息: domain: http://tp5.com file: /index.php url: /index/index/hello/test/ddd.html?name=thinkphp url with domain: http://tp5.com/index/index/hello/test/ddd.html?name=thinkphp url without query: /index/index/hello/test/ddd.html root: root with domain: http://tp5.com pathinfo: index/index/hello/test/ddd.html pathinfo: index/index/hello/test/ddd ext: html 获取当前模块/控制器/操作信息: 模块:index 控制器:Index 操作:hello 获取路由和调度信息: 路由信息: array(0) { } 调度信息: array(2) { ["type"] => string(6) "module" ["module"] => array(3) { [0] => string(5) "index" [1] => string(5) "index" [2] => string(5) "hello" } }
页面跳转的效果图:
相关推荐
非常漂亮美观,操作简单,让你的网站添彩加色,棒棒棒
TP5短链接生成与跳转,短链接生成 地址:http://t.cn/setshorturl.html?sign=xxxxxxxxxxxxxxxxx post参数: urls 原链接地址 必填 title 描述信息 非必填 返回值: { "status": 0, "msg": "短链接生成成功", "data":...
我使用的是Tp5框架,Tp5的跳转提示页面的改写和Tp3的有异曲同工之妙,首先还是先看一下Tp框架中自带的跳转提示页面的代码吧,我直接贴上了: {__NOLAYOUT__}<!DOCTYPE ...
主要介绍了TP5框架页面跳转样式操作,结合实例形式分析了TP5框架移动设备支持及页面跳转样式定义相关操作技巧,需要的朋友可以参考下
【SpringBoot页面跳转访问css、js等静态资源引用无效解决】 解释:SpringBoot项目默认访问根目录有三个分别是: /resources :系统默认的根路径 /static :所有静态资源文件如js、css、jpg、html等文件是可以直接...
Yii里面只能通过setflash()设置提示信息,但是没有封装一个支持跳转的提示信息页面。楼主是从ThinkPHP过来的,所以直接把TP里面的success() error() 以及 ajaxReturn() 单独剥了出来,做成了一个通用的类,在Yii里...
tp5数据库备份操作tp5数据库备份操作tp5数据库备份操作tp5数据库备份操作tp5数据库备份操作tp5数据库备份操作tp5数据库备份操作tp5数据库备份操作tp5数据库备份操作tp5数据库备份操作tp5数据库备份操作tp5数据库备份...
tp5开发的通用后台模板,权限管理+文章管理+幻灯片
ThinkPHP的success并不跳转页面,而是直接输出json字符串的原因.zip 解决ThinkPHP的success并不跳转页面,而是直接输出json字符
TP5练手项目
tp5 微信H5支付 记录一下 再加一个access_token定时刷新
基于tp5下做的excel上传和下载设置了几个字段,根据个人需要设置字段
TP5框架开发
NetBeans 不支持 ThinkPHP 的标签,面对 View 下的各种叹号,以及 HTML 代码无法折叠等问题,一直深深的困扰着我。 然后不小心的发现其实这个是有解决方法的: 把附件解压放到你项目的nbproject下就可以了。...
tp5和tp5.1发送邮件拓展包
tp5精美博客前端,自适应tp5精美博客前端tp5精美博客前端tp5精美博客前端tp5精美博客前端tp5精美博客前端tp5精美博客前端
tp5通用后台.zip tp5通用后台.zip tp5通用后台.zip tp5通用后台.zip