ThinKPHP6.0 上手操作
发布日期:2021-05-09 04:16:31 浏览次数:13 分类:博客文章

本文共 4907 字,大约阅读时间需要 16 分钟。

������ ThinkPHP6.0

cd ������������������������������������������

���������������������composer create-project topthink/think thinkPHP6.0

cd ���������PHP������ thinkPHP6.0 ���������

���������������������.env ������������ // ������ .example.env ���������������

���������������������.env ������ APP_DEBUG = true

���������������������config/app.php ������ show_error_msg = true

���������������������php think run

���������������������php think run -p 80

��������������������� // :������������������

���������������URL������

��������������������������������������������� hosts ���������

Apache

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

Nginx

location / { // ���..������������������   if (!-e $request_filename) {   		rewrite  ^(.*)$  /index.php?s=/$1  last;    }}

���������������������������

������������������php think make:controller Book

���������php think make:model Book

���������������Route::resource('book', 'Book');

���������

0, 'msg' => 'ok', 'data' => $res]); } /** * ���������������������������. * * @return \think\Response */ public function create() { // } /** * ��������������������� * * @param \think\Request $request * @return \think\Response */ public function save(Request $request) { // ������������ $data['title'] = $request->param('title', '������'); $data['c_id'] = $request->param('c_id', '1'); $data['u_id'] = $request->param('u_id', '1'); $data['desc'] = $request->param('desc', '������'); $data['img'] = $request->param('img', '������'); // ������������ // ������������ $res = ModelBook::addOne($data); // ������ if (!$res) { return json(['code' => 1, 'msg' => '���������������', 'data' => $res]); } return json(['code' => 0, 'msg' => 'ok', 'data' => $res]); } /** * ��������������������� * * @param int $id * @return \think\Response */ public function read($id) { $where['id'] = $id; $res = ModelBook::getOne($where); // ������ if (!$res) { return json(['code' => 1, 'msg' => '������������', 'data' => $res]); } return json(['code' => 0, 'msg' => '������������', 'data' => $res]); } /** * ���������������������������. * * @param int $id * @return \think\Response */ public function edit($id) { // } /** * ��������������������� * * @param \think\Request $request * @param int $id * @return \think\Response */ public function update(Request $request, $id) { // ������������ $where['id'] = $id; // ������������ $data['title'] = $request->param('title', '������'); $data['c_id'] = $request->param('c_id', '2'); $data['u_id'] = $request->param('u_id', '2'); $data['desc'] = $request->param('desc', '������'); $data['img'] = $request->param('img', '������'); // ������ $res = ModelBook::upd($where, $data); // ������ if (!$res) { return json(['code' => 1, 'msg' => '������������', 'data' => $res]); } return json(['code' => 0, 'msg' => '������������', 'data' => $res]); } /** * ������������������ * * @param int $id * @return \think\Response */ public function delete($id) { $where['id'] = $id; $res = ModelBook::del($where); // ������ if (!$res) { return json(['code' => 1, 'msg' => '������������', 'data' => $res]); } return json(['code' => 0, 'msg' => '������������', 'data' => $res]); }}

������

'int', 'c_id' => 'int', 'u_id' => 'int', 'title' => 'string', 'desc' => 'string', 'img' => 'string', 'status' => 'int', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; /** * ������������������ * @param array $where ������ */ public static function getOne($where) { return self::where($where)->find(); } /** * ������������������ */ public static function getPage() { return self::alias('b')->join('book_cate c', 'c.id = b.c_id')->field('b.*, c.name as cateName')->paginate(5); } /** * ������������ * @param array $data ������ */ public static function addOne($data) { return self::create($data); } /** * ������ * @param array $where ������ */ public static function del($where) { return self::where($where)->delete(); } /** * ������ * @param array $where ������ * @param array $data ������ */ public static function upd($where, $data) { return self::where($where)->save($data); }}
上一篇:ThinkPHP6.0 容器和依赖注入
下一篇:Laravel - 上手实现 - 邮件发送

发表评论

最新留言

关注你微信了!
[***.104.42.241]2025年04月08日 06时08分26秒