小兔网

这次给大家带来thinkphp之路由别名及绑定,thinkphp之路由别名及绑定的注意事项有哪些,下面就是实战案例,一起来看一下。

1、路由别名

thinkphp之路由别名及绑定17:02:53

thinkphp之路由别名及绑定

thinkphp之路由别名及绑定

使用别名:math代表后面那个路径,访问需要在math后面加上方法、参数

thinkphp之路由别名及绑定

白名单和黑名单:ext表示需要加上后缀

thinkphp之路由别名及绑定

静态数组:

thinkphp之路由别名及绑定

另一个例子:

thinkphp之路由别名及绑定

需要加上根目录,不然会从public开始访问,访问需要在php后面加上方法名

thinkphp之路由别名及绑定

2、路由绑定

a、入口绑定:分两个级别

thinkphp之路由别名及绑定

thinkphp之路由别名及绑定

thinkphp之路由别名及绑定

访问时直接输方法名

thinkphp之路由别名及绑定

b、入口自动绑定:

thinkphp之路由别名及绑定

thinkphp之路由别名及绑定

新建的入口文件:

thinkphp之路由别名及绑定

admin模块下控制器里面的文件

thinkphp之路由别名及绑定

c、动态绑定:

thinkphp之路由别名及绑定

thinkphp之路由别名及绑定

绑定到index模块:

thinkphp之路由别名及绑定

thinkphp之路由别名及绑定

d、绑定到命名空间或者类:直接定位到指定的模块或者指定的控制器

thinkphp之路由别名及绑定

thinkphp之路由别名及绑定

thinkphp之路由别名及绑定

如果将命名空间绑定到app\index\controller,凡是使用该命名空间下的所以控制器都可以直接使用

自定义文件夹下的route文件:

thinkphp之路由别名及绑定

app\index\controller下面有两个类,Dome和Class 访问时可以不写模块名

thinkphp之路由别名及绑定

thinkphp之路由别名及绑定

绑定到当前url类:

thinkphp之路由别名及绑定

thinkphp之路由别名及绑定(访问,直接访问方法)

以上就是thinkphp之路由别名及绑定的知识。速戳>>知识兔学习精品课!