Blogger Information
Blog 10
fans 1
comment 0
visits 9715
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
thinkphp6.0路由的坑
弋兮
Original
2282 people have browsed it

前几天打算开始学习thinkphp框架,就拿最新的版本thinkphp6.0(2019-10-24 02:07 UTC版)来学习,下面说点自己的一点经验与踩的坑。

  1. 首先是安装

       貌似自从thinkphp5.1开始,官方就只提供composer方式下载框架了,composer是 PHP 用来管理依赖(dependency)关系的工具。安装使用起来也很简单,在官网http://www.baidu.com/link?url=HNGeCU4A8gAiQynM7YIj4Lc18Kyu4rZ9IkdoPX4yl040PMk6luTuZbmYLbsSs1aq&wd=&eqid=d4a4770300024f9d000000065db9466d下载安装即可。

        使用composer下载框架要注意,必须在搭建了php环境下的文件目录下踩可以,比如说使用phpstudy搭建的环境根目录是(如果在d盘默认目录为)D:\phpstudy_pro\WWW,要在cmd下cd到此目录下,然后执行对应的composer命令(在composer安装包网站https://packagist.org/搜索topthink,第一个即是thinkphp框架

    1572423972.jpg

2. 然后就是我使用的时候遇到的坑来了

第一个坑如图:

图片.png

这里是需要将public目录下的.htaccess文件里的RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] 加个?号,即RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L].搞定。

图片.png

第二坑是路由route,thinkphp(2019-10-24 02:07 UTC版)将多应用模式独立出来了,需单独下载,具体可见官方手册,也可参考https://www.jianshu.com/p/22c88181e78d

在app\controller\index.php文件里可以看到定义了两个方法index()和hello(),在url中怎么访问第二种方法hello()呢?直接输入域名\index\hello出错

图片.png

这是因为在route\app.php中官方定义了一个路由:Route::get('hello/:name', 'index/hello'); 在地址栏输入:域名\hello\name,即可使用hello()方法,这里的name是实参:图片.png

如果将这个路由注释掉,即可正常访问:域名\index\hello

图片.png

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!