7、TP5中的URL访问
2018-05-17 本文已影响1042人
IUVO
本章主要讲解TP5中的URL访问规则。
TP5支持的URL
模式只有两种,一种是PATH_INFO
,一种是兼容模式。
首先,我们在application
目录下新建一个user
模块文件夹,在文件夹中再新建一个controller
文件夹,controller
文件夹中再新建一个Manager.php
文件,文件内容如下:
<?php
namespace app\user\controller;
class Manager {
public function add($n=0 , $m=0){
return '$n + $m = '. ($n + $m);
}
}
?>
那么,如何用URL访问这个方法呢?
试试看传统模式:
/* index.php为入口文件,m为模块,c为控制器,a为操作方法,n和m为参数 */
http://tp5.com/index.php?m=user&c=manager&a=add&n=1&m=2
你会看到,不是预期的结果,原因是因为传统模式在TP5中已经不再被支持了!
现在来看看能支持的模式:
-
PATH_INFO
模式:
http://tp5.com/index.php/user/manager/add/n/1/m/2
/* 其实就是传统模式的简写 */
- 兼容模式:
根据传参不同可以分为两种:
1、PATH_INFO
方式传参:http://tp5.com/index.php?s=user/manager/add/n/1/m/4
2、传统方式传参:http://tp5.com/index.php?s=user/manager/add&n=1&m=5
