thinkphp5.0 对于thinkphp3.2 几乎是颠覆和重构了,以至于在新学习thinkphp5.0的时候,感觉无从下手。
ThinkPHP 5.0的安装
方式一:官网下载:
方式二:git安装
应用项目:https://github.com/top-think/think
核心框架:https://github.com/top-think/framework
首先Clone项目仓库:
git clone https://github.com/top-think/think tp5
然后再切换到项目文件夹(/tp5),安装核心框架
git clone https://github.com/top-think/framework thinkphp
后续需要更新框架时,只要切换到thinkphp文件夹并执行
git pull https://github.com/top-think/framework
运行ThinkPHP项目
我这边使用的是mamp(大象)来搭载本地服务器还有本地mysql。
下载地址:https://www.mamp.info/en/downloads/
安装使用: http://www.jianshu.com/p/a665a6372e42
配置本地服务器地址:localhost

构建本地数据库:(建表、主键、外键、关联、以及sql增删改查本篇就不做介绍)

将下载后的tp5文件放入htdocs文件夹中:

进入tp5文件夹找到database.php文件,路径修改如下:

进入application->index->controller文件夹,我们在controller文件夹新建一个test.php文件。
test.php 代码如下:
public function index(){
return 'Hello World!';
}
使用如下方式进行访问:http://localhost:8888/tp5/public/index.php/Index/Test/index在index.php后面加上/模块名/控制器名/方法名就可以调用相应的方法了
ps:这个地方贼坑,实际上http://localhost:8888/tp5/public/index.php这个地址对应的是/../application/这样的地址Index 是index文件夹,test是test文件,index是index方法,别问我controller去哪了,我也想知道。当访问该地址出现如下结果的时候,则表明你的本地服务器基本ok,可以访问了。

但是我还是高兴的太早了,当我按照thinkphp3.2的方式,进行接口访问的时候,就

首先,我们还是乖乖创建模型 在index文件夹内创建model文件夹 创建user.php模型

然后,在控制器中倒入模型对象use app\index\model\user;

然后便可以链接本地服务器访问了。
网友评论