一.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