tp5开发小程序商城
一、下载ThinkPHP5.07,放网站根目录下,http://127.0.0.1/zerg/public/访问,出现如下
:)
ThinkPHP V5
就是安装成功。
二、MVC
model 业务层
controller 控制层
view 视图层
三、ThinkPHP 5 结构与路径解析
http://127.0.0.1/zerg/public/index.php/模块名/控制器/方法
http://127.0.0.1/zerg/public/index.php/sample/test/hello
http://z.cn/index.php/sample/test/hello 配置完虚拟域名后的路径,phpstudy8.1版本,可以一键配置。
四、路由
在application文件夹下的route.php里编写以下代码。
use think\Route;
Route::rule('hello', 'sample/Test/hello');
http://z.cn/hello访问,但是报错:No input file specified,解决方法看下面:
TP5配置路由时出现No input file specified
1.我们只需打开public/.htaccess文件;
2.将最后一行的代码改成这样: RewriteRule ^(.*)$ index.php?/$1 [QSA,PT,L]
即在index.php的后面加上?即可。
(视频里3-6,获取请求)
Route::rule('路由表达式','路由地址','请求类型','路由参数(数组)')
5种请求类型 GET,POST,DELETE,PUT,* 默认*请求类型
['https'=>false] 手册-路由-路由参数
//Route::rule('hello','sample/Test/hello','GET',['https'=>false]);//调用rute方法
//Route::rule('hello','sample/Test/hello','GET|POST',['https'=>true]);//支持GET和POST 只支持https
//Route::get('hello/:id','sample/Test/hello');//get路由传递参数 http://127.0.0.1/zerg/public/index.php/hello/33?name=aa
方法里如下这样写
访问http://z.cn/hello/123?name=zhangsan,会输出123|zhangsan
//Route::post('hello/:id','sample/Test/hello');//post路由传递参数 http://127.0.0.1/zerg/public/index.php/hello/33?name=aa
//Route::get('hello','sample/Test/hello');
//Route::post();
//Route::any()
还可以request类获取,use think\Request;
还可以input助手函数 $all = input('get.age'); public function hello(Request $request)依赖注入等等