ThinkPHP? ?? ?? ??? ???? ??
Jun 03, 2023 am 08:01 AM
1. ?? ??
1.1 ??? ??
??? ??? ? ??? ??? ??? ??? ???? ??? ?????. ? ?? hasOne? ?????. () ? alongTo() ??? ???? ??? ?????. ? ?? ??? ???? ??? ?????. ??? ??? ???(user ???)?? ?? ??? ??? ?? ???(userinfo ???)???. ??? ??? ??? ????.
user: id name userinfo: id user_id age
? ? ???? user_id ??? ?? ?????. . ?? ??? ????? ??? ??? ?? ??? ???? ???. ??? ??? ????.
??? ???? ??? ??? ??? ???? userinfo() ???? ?????.
//User模型 <?php class User extends Model{ public function userinfo(){ return $this -> hasOne('UserInfo', 'user_id'); } }
User ???? age() ???? ?????. ? ???? ??? userinfo ??? age ??? ????? ??? ?????.
//User模型 <?php class User extends Model{ protected $readonly = ['age']; public function userinfo(){ return $this -> hasOne('UserInfo', 'user_id'); } public function getAgeAttr($value, $data){ if(isset($data['userinfo'])){ return $data['userinfo']['age']; } return ''; } }
? ??? ??? ? find() ???? ???? ??? ???? ??? ??? ? ????.
//查詢user表中id為1的用戶 $user = User::get(1); echo $user -> name; echo $user -> age;
??: ? ????? $readonly ??? ???? $readonly ??? ??? ????. ThinkPHP ?? ??? ??????? ???? ??? ??? ? ?? ??? ?????. ? ????? age ??? ?? ?? ???? ???? $user -> age? ???? ? getAgeAttr ???? ???? ???? userinfo ??? age ??? ?????.
1.2 ??? ??
??? ??? ? ??? ??? ? ??? ?? ???? ?? ?? ????? ??? ???? ??? ?????. ?? ?? ??:
order: id user_id order_no order_goods: id order_id name price
?? ? ???? order_id ??? ?? ???? ????. ?? ??? ????? ???? ?? ??? ?? ?? ??? ??? ???. ???? ??? ??? ????.
??? ???? ??() ???? ?????. ? ???? ???? ?? ??? ??? ??? ?????.
//User模型 <?php class User extends Model{ public function orders(){ return $this -> hasMany('Order', 'user_id'); } }
?? ???? ??() ???? ?????. ? ???? ??? ?? ??? ??? ?????.
//Order模型 <?php class Order extends Model{ public function goods(){ return $this -> hasMany('OrderGoods', 'order_id'); } }
? ??? ??? ? find() ???? ???? ???? ??? ? ??? ???? ??? ??? ? ????.
//查詢user表中id為1的用戶的訂單信息和訂單的商品信息 $user = User::get(1, 'orders.goods'); var_dump($user -> orders[0] -> goods);
??? ????('orders.goods')? ?? ??? ???? ?? ?????. ??? ?? ? ?? ?? ?? ??.
2. ?? ??
2.1 ?? ?? ??
?? ?? ???? ?? ??? ???? ??? ?? ??? ??? ?? ??? ???? ?? ??? ??? ? ????. ?? ??, ?? ???? ?? ?? ??? ????? ???.
$user = User::get(1); $orders = $user -> orders; echo $user -> name; foreach($orders as $order){ echo $order -> order_no . "\n"; }
2.2 ??? ??
??? ??? ? ???? ??? ???? ???? ??? ??? ???? ? ?? ??? ??? ? ????. . ?? ?? ??? ????.
$user = User::with('orders')->get(1);
? ???? $user ??? ??? ? with() ???? ??? ????? ??????. ?? ?? ?? ????? ??? ???? ???? ????. ?? ??? ???????.
2.3 ?? ??
?? ??? ?? ??? ?? ?? ??? ???? ?? with ??? ?? true ?? ??? ???? ?? ??? ???? ??? ?? ????. ?:
$user = User::with('orders')->find(1, true);
? ???? find() ???? true ????? ??????. ? ????? ??? ??? ?? ??? ????? ?? ?????.
? ??? ThinkPHP? ?? ?? ??? ???? ??? ?? ?????. ??? ??? 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 ?????? ??? ??? ???? ? ?? ??? ??? ?????.
