?? ? ?????? ?? ????? ?? ??????? ? ??????? PHP ??? ???? ?????. ?? ThinkPHP ?????? ?? PHP ????? ??? ??? ? ?????. ???? ??? ??? ?? ???? ?? ?? ?? PHP ????? ? ??? ?????. ? ????? ThinkPHP6 ?????? ??? ??? ?? ???? ??? ??????? ? ??????? ??? ????.
1. ?? ? ??
?? ?? ??? PHP? ??????(MySQL ?), ??? Composer ??? ???? ???? ???.
? ??? ?? ??? ThinkPHP6 ?????? ?????? ?? ??? ??? ?? ????? ?????. ?? ?? ??? ??? "composer install" ??? ???? ?????? ??? ?? ?????? ????? ?????.
?? ?? ????? ???? ???. ?? ????? ?? ??? .env ??? ???? .env.example ??? ??? .env ??? ????. ??, /config/database.php ??? ??????? ???? ?????? ?? ??? ?????.
?????, ?????? ???? ?? ???? ????? ?? ?????? "php think migration:run" ??? ???? ???.
2. ???? ? ?? ???
ThinkPHP6 ??????? ????(Controller)? HTTP ??? ???? ? ???? ?? ???? ?? ??? ?????? ?????. ??? ??????? ???? ???? ??? ???? ?????.
? ???? ??? ????? ?? ??? ??? ????. /app/controller ??? User.php ??? ???? ?? ??? ?????.
<?php namespace appcontroller; use thinkacadeDb; use thinkacadeRequest; class User { public function getAllUser() { $userList = Db::table('user')->select(); return json_encode($userList); } public function getUserById($id) { $user = Db::table('user')->where('id', $id)->find(); return json_encode($user); } public function addUser() { $data = Request::param(); Db::table('user')->insert($data); return 'Add Successfully'; } public function updateUser($id) { $data = Request::param(); Db::table('user')->where('id', $id)->update($data); return 'Update Successfully'; } public function deleteUser($id) { Db::table('user')->where('id', $id)->delete(); return 'Delete Successfully'; } }
/app/model ??? User.php ??? ???? ?? ??? ?????.
<?php namespace appmodel; use thinkModel; class User extends Model { protected $table = 'user'; }
3. ?? ? ? ??
ThinkPHP6 ??????? Route? ?? ???? ? ???? URL? ???? ? ????, View? ????? ???? ??? ??? ? ???? ???? ? ?????.
? ???? ?? ??? ??????.
- GET /user: ?? ??? ??? ???? getAllUser ???? ???? ?? ?????.
- GET /user/:id: ??? ID? ???? ??? ??? ????, getUserById ???? ???? ?????.
- POST /user: ? ???? ???? addUser ???? ???? ?????.
- PUT /user/:id: ??? ID? ???? ??? ??? ??????, updateUser ???? ???? ?????.
- DELETE /user/:id: ??? ID? ???? ???? ????? deleteUser ???? ?????.
/app/route.php ??? ?? ??? ?????.
<?php use thinkacadeRoute; Route::get('/user', 'User/getAllUser'); Route::get('/user/:id', 'User/getUserById'); Route::post('/user', 'User/addUser'); Route::put('/user/:id', 'User/updateUser'); Route::delete('/user/:id', 'User/deleteUser');
?? ?? /app/view ?? ??? User ??? ??? index.html, edit.html, add.html ?? ????. ??? ???.
index.html ????? ?? ???? ??? ? ????. edit.html, add.html ????? ??? ??? ???? ??? ? ????.
????? ????? ?? ? ??? ??? ?????. ?? ?? ??? ?????? ?? ??? ??? ? ????.
public function all() { return view('index')->assign('userList', Db::table('user')->select()); } public function edit($id) { return view('edit')->assign('user', Db::table('user')->where('id', $id)->find()); } public function add() { return view('add'); }
4. ??? ?? ??
?????? ?? ? ???????? ??? ??? ?? ??? ?????. ThinkPHP6 ????? ??? Auth ????? ?? ???? ??? ??? ??? ??? ? ????.
?? /config/auth.php ???? ?? ?? ??? ?? ???.
???? ????? Auth ?????? ???? ???, ????, ?? ? ?? ??? ???? ??? ?? ??? ??? ? ????. ?? ?? ??? ?????? ?? ??? ??? ? ????.
<?php namespace appcontroller; use appmodelUser as UserModel; use thinkacadeDb; use thinkacadeRequest; use thinkacadeSession; use thinkacadeView; use thinkuthAuth; class User { public function login() { if (Request::isPost()) { $data = Request::param(); if (Auth::attempt(['username' => $data['username'], 'password' => $data['password']])) { Session::flash('success', 'Login successfully.'); return redirect('/index'); } else { Session::flash('error', 'Login failed.'); return view('login'); } } else { return view('login'); } } public function register() { if (Request::isPost()) { $data = Request::param(); $userModel = new UserModel(); $userModel->save($data); return redirect('/login'); } else { return view('register'); } } public function logout() { Auth::logout(); Session::flash('success', 'Logout successfully.'); return redirect('/login'); } public function check() { $user = Auth::user(); if (!$user) { Session::flash('error', 'You are not logged in.'); return redirect('/login'); } return $user; } }
5. API ????? ??
?????? ?? ? ???????? API ?????? ?? ??? ?????. ThinkPHP6 ????? ??? ?? ?? ??? ??? ???? API ?????? ??? ? ????.
? ???? ?? API ?????? ??????.
- GET /api/user: ?? ??? ??? ???? getAllUser ???? ???? ?? ?????.
- GET /api/user/:id: ??? ID? ???? ??? ??? ???? getUserById ???? ???? ?????.
- POST /api/user: ? ???? ????? addUser ???? ?????.
- PUT /api/user/:id: ??? ID? ???? ??? ??? ??????, updateUser ???? ???? ?????.
- DELETE /api/user/:id: ??? ID? ???? ???? ????, deleteUser ???? ???? ?????.
??????? API ????? ??, ?? ??, ?? ????, ?? ?? ? ?? ?? ???? ???? ???.
?? ?? ??? ?????? ?? ??? ??? ? ????.
<?php namespace appcontroller; use appmodelUser as UserModel; use thinkacadeDb; use thinkacadeRequest; class User { // ... public function getAllUser() { $userList = Db::table('user')->select(); return json($userList); } public function getUserById($id) { $user = Db::table('user')->where('id', $id)->find(); return json($user); } public function addUser() { $data = Request::param(); Db::table('user')->insert($data); return 'Add Successfully'; } public function updateUser($id) { $data = Request::param(); Db::table('user')->where('id', $id)->update($data); return 'Update Successfully'; } public function deleteUser($id) { Db::table('user')->where('id', $id)->delete(); return 'Delete Successfully'; } }
6. ? ?????? ??
?????? ?? ? ??????? ??? ??? ??? ???? ?? ?? ??? ???? ???. ?? ?? ???? ??? ?? ??? ???? ???.
- ??: ?? ???? ?? ??????? ??? ???? ???. ?? ?? ??? ???? ????? ???? ??? ????? ?????? ??? ?????.
- ?? ???: ?? ???? ?? ??????? ?? ???? ???? ???. ?? ??, ?? ??? ???? ??? ??? ??? ???, Gzip ??? ????? ??? ???? ??? ? ?????? ??? ??????.
- ???? ? ?? ??: ?? ???? ?? ??? ???? ? ?? ?? ???? ???? ???. ?? ??, ???? ?? ??? ???? ?? ??? ????, ???? ??? ???? ??????? ?? ??? ????? ?????? ? ??????? ???? ??? ?????.
IV. ??
? ??? ?? ThinkPHP6 ?????? ???? ???? ??? ??????? ? ??????? ???? ?? ??? ??? ?????. ?? ?? ????? ?? ??? ?? ??? ??? ???? ???? ? ?? ? ??????? ??? ? ????.
? ??? ThinkPHP6? ?? ??? ??????? ? ?????? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

ThinkPHP ????? ????? ??? ?????: Composer? ????, ???? ????? ???? php bin/console? ????, ?? ???? ??? http://localhost:8000? ?????.

ThinkPHP?? ??? PHP ????? ??? ?? ??? ????. ??? ???? 3.2, 5.0, 5.1, 6.0? ????, ??? ??? ??? ???? ??? ??? ???? ? ?????. ?? ?? ??? ThinkPHP 6.0.16???. ??? ??? ? PHP ??, ?? ?? ?? ? ???? ??? ??????. ??? ??? ??? ???? ?? ?? ??? ???? ?? ????.

ThinkPHP Framework? ???? ???? ??: ThinkPHP Framework? ?? ????? ?????? ??? ???. ThinkPHP ?? ????? ???? ?? ???(?? ??)? ????. ?????? ?? ????? ?????. ? ??? ?????. ThinkPHP ??????? ??????. ThinkPHP ?????? URL? ???? ?????.

Laravel? ThinkPHP ?????? ?? ??: ThinkPHP? ????? ??? ? ??? ??? ?? Laravel?? ??? ????. Laravel? ? ????? ??? ??????? ?? ThinkPHP? ? ??? ? ????.

ThinkPHP ?? ??: PHP, Composer ? MySQL ??? ?????. Composer? ???? ????? ????. ThinkPHP ?????? ???? ?????. ?????? ??? ?????. ?????? ??? ?????. ??????? ???? http://localhost:8000? ?????.

ThinkPHP? ?? ????, ?? ???, ?? ?? ? ?????? ???? ?? ??? ?? ??? PHP ????????. ?? ?? ???? ??? ?? 10,000? ??? ??? ??? ? ??? JD.com, Ctrip? ?? ??? ? ??? ? ?????? ????? ?? ?? ?????? ?? ?????.

?? ??: API ??? ?? ThinkPHP ?????? ???? ?? ???? ????? ????? API(?? ????? ?????)? ???? ?? ? ??? ????. API? ??? ??, ?? ?? ? ?? ??? ??? ? ??? ????? ??? ???? ?? ?? ??? ?????. ??? PHP ?? ?????? ThinkPHP ?????? ????? ?? ???? ???? ????.

"?? ??: ThinkPHP ?????? ???? ??? ??? ???? ??" ??? ??? ??? ???? ?? ? ?? ????? ?? ?? ?? ??? ??? ???? ??? ???? ?? ?? ??? ?? ? ??????. ??? ??? ??? ??? ????? ?? ???? ??? ???, ?? ??? ??, ??? ?? ?? ?? ??? ?? ??? ??? ???? ?? ??? ??? ???? ?? ?? ?????. PHP ???? ?? ???? ?? ?????? ThinkPHP ?????? ??? ??? ???? ? ?? ??? ??? ?????.
