thinkphp5.1 后台开发
2022-07-28 14:14:58
140
{{single.collect_count}}

Mac 12.2

brew install php@7.4

brew install composer

环境变量最好配置一下,有时候系统升级就失效了

 zsh---------

配置默认Python版本  PHP composer 

vim ~/.zprofile

alias python="/opt/homebrew/bin/python3.9"export PATH=/opt/homebrew/Cellar/php@7.4/7.4.21_1/bin:$PATHexport PATH=/opt/homebrew/Cellar/composer/2.1.3/bin:$PATH

source ~/.zprofile

bitnami mamp stack 7.1

找到htdocs

composer create-project topthink/think=5.1.x-dev ad5 .1安装最新版

composer update topthink/framework 跟下库修复错误

配置bitami

找到vhost 文件

<VirtualHost *:7070>ServerName ad.cnServerAlias ad.cnDocumentRoot "/Users/xiaodunmeng/Applications/mampstack-7.1.33-0/apache2/htdocs/ad5.1/public"<Directory "/Users/xiaodunmeng/Applications/mampstack-7.1.33-0/apache2/htdocs/ad5.1/public">Options Indexes FollowSymLinksAllowOverride All<IfVersion < 2.3 >Order allow,denyAllow from all</IfVersion><IfVersion >= 2.3 >Require all granted</IfVersion></Directory></VirtualHost>

打开host   utools  插件里面有

127.0.0.1 ad.cn

开启mamp    端口号自定义

ad.cn:7070

看到欢迎页面就好了


配置数据库   database

路由定义   

Route::rule('new','index/index/hello');

   ad.cn/new   

访问的是  index 下面 hello 方法


数据库操作   具体看文档

查询数据 · ThinkPHP5.1完全开发手册 · 看云 (kancloud.cn)

public function ce(){//只要前一条数据$data = Db::table('aq_user')->where('id',1)->find();// 找到id=1的所有数据$da = Db::table('aq_user')->where('id', 1)->select();return json($data);}

模型操作

index/model

指定表

class User extends Model{protected $table = 'aq_user';}
public function tes() {$data = User::get(1);return json($data);}

分页:

 public function avData(Request $request){$pageNum = $request->param('pageNum');$pageSize = $request->param('pageSize');if (!$pageNum) $pageNum = 1;if (!$pageSize) $pageSize = 10;$list = Db::table('testav')->page($pageNum, $pageSize)->select();if ($list) {$count = Db::table('testav')->count('id');$res = ['list' => $list,'pageNum' => $pageNum,'pageSize' => $pageSize,'total' => $count];return json($res);} else {return json(['code'=>404, 'msg' => '请求失败', data=>[]]);}}

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}