1.php的URL访问

一.URL解析

1. ThinkPHP 框架非常多的操作都是通过URL来实现的;

2. 多应用:http://serverName/index.php/应用/控制器/操作/参数/值…;

3. 单应用:http://serverName/index.php/控制器/操作/参数/值…; 4

. 由于TP6.0默认是单应用模式,多应用需要作为扩展安装,避免混乱暂时搁置;

5. http://serverName 是域名地址,比如127.0.0.1:8000或localhost/tp6/

6. index.php 这个文件,是根目录下public/下的index.php(入口文件);

7. 控制器:app目录下有一个controller控制器目录的Test.php(控制器);

8. Test.php 控制器的类名也必须是class Test,否则错误;

9. 操作就是控制器类里面的方法,比如:index(默认免写)或hello(必写);

10. 那么完整形式为:

a. http://localhost/tp6/public/index.php/test/hello/value/world

b. http://127.0.0.1:8000/index.php/test/hello/value/world

class Test
 {
 public function index()
 {
 return 'test';
 }
 public function hello($value = '')
 {
 return 'hello '.$value;
 }
 }

11. public/index.php 中的 index.php 可以省略,只要设置URL重写即可;

12. httpd.conf 配置文件中加载了mod_rewrite.so模块;

13. AllowOverride None 将None 改为 All;

14. 此时,路径变更为: http://localhost/tp6/public/test/hello/value/world

二.URL兼容模式 1. 上个要点已经了解了URL所有访问规则,通过创建Test控制器更加了解;

2. 如果上面那种形式的URL不支持的话,可以使用兼容模式的方式来访问: http://localhost/tp6test3/public/?s=test/hello/value/world

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值