thinkphp框架的路径问题
来源:互联网 发布:js 鼠标轨迹 编辑:程序博客网 时间:2024/06/05 19:52
问题回顾:
将环境迁移后,首页可以访问,但是后面的url链接都出现问题,只要一点击就出现,无法加载模块
第一时间想到的是url的跳转问题,于是检查nginx的配置文件,但是我们这边是一级域名,这样跳转是没有问题的
location / { if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; break; } }
后来在网上也找了很多文章,但是都没有解决这个问题
直到我看到这篇文章:thinkphp框架的路径问题 - 总结
TP中有不少路径的便捷使用方法,比如模板中使用的__URL__,__ACTION__等,如果你对这些路径不是很明白,用起来说不定就会有这样或那样的问题,抑或出了错也不知道怎么改,现在我们看一下这些路径到底是代表了什么吧! 假如你项目首页的URL是:www.test.com/other/Form 假如当前模块是:Index 假如当前操作是:index那么首页完整的URL:http://www.test.com/other/Form/index.php/Index/index __ROOT__:/other/thinkphp/mydemo __SELF__:/other/thinkphp/mydemo/Form/index.php __ACTION__: /other/thinkphp/mydemo/Form/index.php/Index/index __URL__: /other/thinkphp/mydemo/Form/index.php/Index __APP__: /other/thinkphp/mydemo/Form/index.php__PUBLIC__:/other/thinkphp/mydemo/Public ../public(不区分大小写):/other/thinkphp/mydemo/Form/Tpl/default/PublicAPP_PUBLIC_URL:/other/thinkphp/mydemo/Form/Tpl/default/PublicWEB_PUBLIC_URL:/other/thinkphp/mydemo/Public模板中对路径部分的操作是这样子的: PHP代码 //项目公共目录 $tmplContent = str_ireplace('../public',APP_PUBLIC_URL,$tmplContent); //网站公共目录 $tmplContent = str_replace('__PUBLIC__',WEB_PUBLIC_URL,$tmplContent); //网站根目录 $tmplContent = str_replace('__ROOT__',__ROOT__,$tmplContent); //当前项目地址 $tmplContent = str_replace('__APP__',__APP__,$tmplContent); //当前模块地址 $tmplContent = str_replace('__URL__',__URL__,$tmplContent); //当前项目操作地址$tmplContent = str_replace('__ACTION__',__ACTION__,$tmplContent); //当前页面操作地址 $tmplContent = str_replace('__SELF__',__SELF__,$tmplContent); 1、路径问题我的TP心得:“路径问题,是个大问题!” 针对THINKPHP2.0,我发现以下名称和对应的路径为:假如你项目首页的URL是:http://<servername>/openexam/ 假如当前模块是:Index 假如当前操作是:index那么首页完整的URL:http://<servername>/openexam/index.php/Index/index __ROOT__:http://<servername>/openexam/ __SELF__:http://<servername>/openexam/index.php __ACT ION__: http://<servername>/openexam/index.php/Index/index __URL__: http://<servername>/openexam/index.php/Index__APP__: http://<servername>/openexam/index.php APP_PUBLIC_URL:http://<servername>/openexam/Tpl/default/Public 注意:以上缩写仅适用于模板中使用,如在php中则使用U方法做URL路由来实现有很多人在THINKPHP下使用jQuery框架,但不 知如何加入。 我发现,多数问题都是路径问题。我的项目架构是:http://localhost/openexam/ 在 C:\xampp\htdocs\Openexam\下放着一个名为script的文件夹,里面是jquery-1.4.1.js。 所以,在 C:\xampp\htdocs\Openexam\Tpl\default\Index\studentLogin.html中,使用: <html> <head> <meta http-equiv="Content" <title>{$title}</title><script src="__ROOT__/Openexam/script/jquery-1.4.1.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready( function(){ alert("ok"); } ) </script> </head> <body> <form method="POST" action=""> Openexam欢迎您,请您登录:<br> ...... </body> </html> 即 可。
我有想到可能还是路径的问题,于是我就检查了这边的路径:
所以这次我就在之前的URL(http://www.zljianjie.comjiekuanpt/)前面又加上了一级目录,
http://www.zljianjie.com/guanwang/jiekuanpt/ 访问正常
这时我在nginx的配置文件里面修改了url跳转的地址:
location / { if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/Guanwang/$1 last; break; } }
重启nginx服务,访问正常!
备注:
可能有一些人会有疑问,为什么我url这边 http://www.zljianjie.com/guanwang/jiekuanpt/
guanwang字段是小写,而我nginx的配置文件中是/index.php/Guangwang/$1,这个是大写的?
在网站根目录下面的 ./Application/Guanwang/Conf/的config.php 文件里面参数:
'URL_CASE_INSENSITIVE' => true, //默认false 表示URL区分大小写 true则表示不区分大小写'URL_MODEL' => 2, //URL模式 0:普通模式 1:PATHINFO模式 2:REWRITE模式 3:兼容模式'VAR_URL_PARAMS' => '', // PATHINFO URL参数变量'URL_PATHINFO_DEPR' => '/', //PATHINFO URL分割符'URL_ROUTER_ON' => true, //开启路由
1 0
- thinkphp框架的路径问题
- thinkphp框架的路径问题 - 总结
- 关于ThinkPHP框架项目在二级目录时,__PUBLIC__路径的问题
- thinkphp的项目路径的问题
- thinkphp的项目路径的问题
- thinkphp js路径问题
- ThinkPhp路径访问问题
- thinkphp js路径问题
- thinkphp框架学习中遇到的问题
- Thinkphp框架的重定向问题
- Thinkphp中的文件路径问题
- 关于thinkphp的几个问题:css路径问题,关联模型,
- ThinkPHP框架的使用
- ThinkPHP框架的使用
- thinkPHP的MVC框架
- thinkphp 框架的 URL_MODEL
- 解决 nginx 服务器不支持 ThinkPHP 框架的问题
- 关于浏览器URL重写的问题(Thinkphp框架):
- gcc的使用
- 自定义上下文对话框
- Linux目录结构和常用命令
- poj 1189 DP
- Qt Coordinate System
- thinkphp框架的路径问题
- Linux学习笔记23 --LDAP网络用户账户
- 把windows里面的文件复制到linux系统中
- 语音信号预处理及特征参数提取
- 图文笔记,带你走进《未来简史》(31-35)
- 达内课程-运算符号
- 通過XML設置屏幕方向(android:screenOrientation)详解
- javase复习整理(一):基础要点、重点、易错点、多线程梳理总结
- 学习Unity(1)基本概念和操作