??? ????? ???? ???? ????? ??? ?? ? ??? ????.
1. ????? ??
1 ?? ??? ??: ??? ???? ????? ?? ????? ???
php? ?????. make:listener
?:
php make:listener UserListener
? ?? ? ???? ?? ????>app
listener下生成
UserListener ???? ?? ???? ?????.
2. ?? ??: ???? ?? ????>appevent.php ??? ?? ???? ??? ?? UserListener ???? ?????.
3. ?? ???: ??? ????? ?? ?? ?? ??? ?????'listen' => applistenerUserListener']
],
event('testEvent');??: ???? testEvent ????? ???? ??? ? ?? ??? ????? event.php? ?? ??? ??? ? ??? ?????. ????? ??? ? ? ?? ????? ??? ? ????. ?? ???? ????? ? ?? ????? ?? UserListener ???? ?? ???? ??? ? ????. (??? ????? ???? ??? ?? ?? ?? ??? ?? ????? ????.) 4. ?? ?? ??: UserListener ???? ?? ????? ???? ?? ?? ?? ??? ??? ????. Other: ???? ???? ???
<?php namespace app\controller; class Other { public function hello() { echo 'hello function'; } }Index: ??? ????? ???
UserListener: ??? ?? ???<?php namespace app\listener; class UserListener { /** * 事件監(jiān)聽處理 * * @return mixed */ public function handle($event) { //當調(diào)用Index類的test1方法時該代碼有效,$event為null var_dump($event); //當調(diào)用Index類的test2方法時該代碼有效,$event為字符串hello var_dump($event); //當調(diào)用Index類的test3方法時該代碼有效,$event為Index類的實例 //可以訪問Index類的name變量 echo $event->name; //當調(diào)用Index類的test4方法時該代碼有效,$event為Other類的實例 //可以調(diào)用Other類的hello方法 echo $event->hello(); } }2. ??? ??1. ?? ???? ?????????? ??? ???? ????? ?? ????? ?????.php make:subscribe ?? ?? ??? ??>?:php think make:subscribe UserSubscribe?? ? UserSubscribe ???? ???? ?? ????>appsubscribe ??? ?????. 2. ???? ???? ?? ????>appevent.php ??? ?? ???? UserSubscribe ???? ??? ?? ?????.'subscribe' => ['appsubscribeUserSubscribe'],??: ??? ?????? ??? ??? UserListener? Listen ???? ???? ???3. Trigger listening? ?? ??? ??4. Listening ??? ???? ???? ? ??? ????. ??? ?? ???? ?? ?????? ????. ?? ???? ?? ???? ?? ?????? ? ? ??? ??? ? ????. 4.1 ?? ??????? ??? ???? ontestEvent ???? UserSubscribe ???? ???? ???. ???? ??? ??? ??? ??? ? ???, ??? ?? ?? ???? ?? ???? ???. event.php?? ??? ??? ??? testEvent??? ??? ??? ontestEvent???(???? ??). Listening ???? ??? ??? ???? ???? ?????? ?? ?????? ???. ?? ??? ??? ????Other ? Index ???? ??? ? ?? ?? ??? ?????.UserSubscribe: ??? ?? ???<?php namespace app\subscribe; class UserSubscribe { public function ontestEvent($user) { //當調(diào)用Index類的test1方法時該代碼有效,$event為null var_dump($user); //當調(diào)用Index類的test2方法時該代碼有效,$event為字符串hello var_dump($user); //當調(diào)用Index類的test3方法時該代碼有效,$event為Index類的實例 //可以訪問Index類的name變量 echo $user->name; //當調(diào)用Index類的test4方法時該代碼有效,$event為Other類的實例 //可以調(diào)用Other類的hello方法 echo $user->hello(); } }4.2 ?? ????? ??? ???? ??? ???? ????. ?? ???? ??. ??? ???? ????? ?? ????? ???? ?????.php think make:event
?:
php think make:event UserEvent
?? ?? ? ???? ???? ????? ?? ?? ???? ?????. ??? ??? ???? ???? ??? ??? ??? ? ????. ?? ???? ??? ?? ????? ??? ? ????. ????, Event ??? ????? ??? ?? ?? ???? UserSubscribe ???? ?????. ?? ?? ??? ???? ? ??? ?? UserEvent ???? ?? ???? ??????.?? ? < ;The UserEvent ???? ????? ?? ????>appevent ??? ?????.
$event->listen('testEvent', [app('app\event\UserEvent'), 'handle']);?? ??? ??? ????Other ? Index ???? ??? ? ?? ?? ??? ?????.UserSubscribe: ??? ?? ???UserEvent: ??? ?? ???<?php declare (strict_types = 1); namespace app\event; class UserEvent { public function handle($user) { //當調(diào)用Index類的test1方法時該代碼有效,$user為null var_dump($user); //當調(diào)用Index類的test2方法時該代碼有效,$user為字符串hello var_dump($user); //當調(diào)用Index類的test3方法時該代碼有效,$user為Index類的實例 //可以訪問Index類的name變量 echo $user->name; //當調(diào)用Index類的test4方法時該代碼有效,$user為Other類的實例 //可以調(diào)用Other類的hello方法 echo $user->hello(); } }? ??? 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 ?????? ??? ??? ???? ? ?? ??? ??? ?????.
