thinkphp5(tp5)路由的使用

1、将.htaccess文件里填上

<IfModule mod_rewrite.c>

Options +FollowSymlinks -Multiviews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]

</IfModule>

代码。

2、找到route.php文件,写上测试内容。如下

use think\Route;

Route::rule(['news/test'=>'index/News/test']);

这个路由是独立路由,当然也可以做成群组路由,如Route::rule(['news/test'=>'index/News/test','article/index'=>'index/article/index']);

3、在index模块下创建News.php类文件,文件内容如下

<?php

namespace app\index\controller;

use think\Controller;

class News extends controller{

    function test(){

    echo 34;die;

    }

}

4、在谷歌地址栏填写url,如www.test.ff/index.php/news/test,然后会看到输出34字样,证明你成功了,注意不要复制我这里的代码,我这里的代码有中文的逗号等。一定自己写哦

猜你喜欢

转载自blog.csdn.net/weixin_36562804/article/details/80096117