ÔõÑùʹÓÃThinkPHP6¾ÙÐÐÎïÁ÷×·×Ù²Ù×÷£¿
Ëæ×ŵç×ÓÉÌÎñÐËÆð£¬È«ÇòÎïÊ¢ÐÐÒµÈç»ðÈçݱ¡£¹ØÓÚÏûºÄÕ߶øÑÔ£¬Äܹ»ÊµÊ±ÏàʶÎïÁ÷ÐÅÏ¢ÏԵøñÍâÖ÷Òª£¬¶ø¹ØÓÚµçÉÌÆóÒµ£¬ÔòÐèÒªÒ»¸öÓÅÒìµÄÎïÁ÷×·×Ùϵͳ£¬ÒÔ±ã¸üºÃµØÖÎÀíÀ¿ÊÕ¡¢ÔËËͺͽ»¸¶µÈ»·½Ú¡£±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃthinkphp6¾ÙÐÐÎïÁ÷×·×Ù²Ù×÷¡£
Ò»¡¢ThinkPHP6¼ò½é
ThinkPHPÊÇÒ»¿îÖÜÈ«ÇÒ¸ßЧµÄPHP¿ò¼Ü£¬ÒѾ±»ÆÕ±éʹÓúÍÈÏ¿É¡£ThinkPHP6ÊÇ×îа棬¾ßÓÐÄ£¿é»¯¡¢×¢½â·ÓÉ¡¢ÒÀÀµ×¢ÈëµÈ¶àÏîÓŵ㣬Äܹ»×ÊÖú¿ª·¢Õß¿ìËÙ¹¹½¨WebÓ¦ÓóÌÐò¡£
¶þ¡¢ÎïÁ÷×·×ÙϵͳÉè¼Æ
1.Ä£¿éÉè¼Æ
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ƾ֤ÎïÁ÷×·×ÙµÄÓªÒµÁ÷³Ì£¬¿É½«ÎïÁ÷×·×Ùϵͳ·ÖΪÈçÏÂÄ£¿é£º
Óû§Ä£¿é£º×¢²á¡¢µÇ¼¡¢ÐÞ¸ÄÃÜÂëµÈ¹¦Ð§¡£
ÎïÁ÷Ä£¿é£º°üÀ¨ÎïÁ÷¹«Ë¾ÐÅÏ¢¡¢Ô˵¥ÐÅÏ¢µÈ¡£
ÔË·ÑÄ£¿é£ºÆ¾Ö¤»õÎïÖØÁ¿¡¢ÖÖÀà¡¢¾àÀëµÈ²ÎÊýÅÌËãÔË·Ñ¡£
¶©µ¥Ä£¿é£º°üÀ¨Ïµ¥¡¢Ö§¸¶¡¢×÷·Ï¡¢ÅÌÎʵȹ¦Ð§¡£
ͶËßÄ£¿é£º´¦ÀíÓû§¹ØÓÚÎïÁ÷ЧÀ͵ÄͶËß¡£
ÖÎÀíԱģ¿é£ºÅÌÎʶ©µ¥¡¢ÎïÁ÷ÐÅÏ¢¡¢´¦ÀíͶËߵȹ¦Ð§¡£
2.ÊÖÒÕÑ¡ÐÍ
¿ò¼Ü£ºThinkPHP6
Êý¾Ý¿â£ºMySQL
»º´æ£ºRedis
ÐÂÎÅÐÐÁУºRabbitMQ
Èý¡¢ÎïÁ÷×·×ÙϵͳµÄÏêϸʵÏÖ
1.×°ÖÃThinkPHP6
ÔÚÍâµØ»òЧÀÍÆ÷ÉÏ×°ÖÃThinkPHP6£¬Ïêϸ°ì·¨¿É²Î¿¼ThinkPHP¹Ù·½Îĵµ¡£
2.½¨ÉèÊý¾Ý¿âºÍÊý¾Ý±í
½¨ÉèÒ»¸ö°üÀ¨Óû§¡¢ÎïÁ÷¡¢¶©µ¥µÈÊý¾Ý±íµÄÊý¾Ý¿â£¬²¢»®·ÖÉè¼Æ±í½á¹¹¡£ÔÚThinkPHP6ÖУ¬¿ÉʹÓÃÊý¾Ý¿âǨá㹤¾ßMigrateÀ´½¨ÉèºÍÖÎÀíÊý¾Ý¿â±í£¬ÔÚTerminalÖÐʹÓÃÒÔÏÂÏÂÁîÆôÓÃMigrate£º
php think migrate:run
µÇ¼ºó¸´ÖÆ
3.±àдģ×Ó
Ä£×Ó£¨Model£©ÊÇÊý¾Ý¿â²Ù×÷µÄ½¹µã£¬ÔÚThinkPHP6ÖеÄÄ£×Ó¼ÌÐø×ÔBaseModelÀ࣬¿ÉÒÔ¼ò»¯Êý¾Ý±íµÄÔöɾ¸Ä²é²Ù×÷¡£ÀýÈ磬ÒÔÏÂÊǶ©µ¥Ä£×ÓÉè¼ÆµÄÊ÷Ä£´úÂ룺
namespace appcommonmodel; use thinkModel; class Order extends Model { protected $table = 'order'; // ¹ØÁªÓû§Ä£×Ó public function user() { return $this->belongsTo('User'); } // ¹ØÁªÎïÁ÷Ä£×Ó public function express() { return $this->belongsTo('Express'); } // ÅÌÎʶ©µ¥Áбí public function getOrderList() { $orderList = $this->with(['user','express'])->paginate(5); return $orderList; } // ÅÌÎʶ©µ¥ÏêÇé public function getOrderDetail($orderId) { $orderDetail = $this->with(['user','express'])->find($orderId); return $orderDetail; } }
µÇ¼ºó¸´ÖÆ
4.±àд¿ØÖÆÆ÷
¿ØÖÆÆ÷£¨Controller£©ÊÇWebÓ¦ÓóÌÐòµÄ½¹µã£¬ÈÏÕæÎüÊÕÇëÇóºÍŲÓÃÏìÓ¦µÄÄ£×Ó¾ÙÐд¦Àí¡£ÒÔÏÂÊǶ©µ¥¿ØÖÆÆ÷Éè¼ÆµÄÊ÷Ä£´úÂ룺
namespace appindexcontroller; use thinkController; use appcommonmodelOrder as OrderModel; class Order extends Controller { // ÅÌÎʶ©µ¥Áбí public function getOrderList() { $orderModel = new OrderModel(); $orderList = $orderModel->getOrderList(); return $this->fetch('order_list', ['orderList' => $orderList]); } // ÅÌÎʶ©µ¥ÏêÇé public function getOrderDetail($orderId) { $orderModel = new OrderModel(); $orderDetail = $orderModel->getOrderDetail($orderId); return $this->fetch('order_detail', ['orderDetail' => $orderDetail]); } }
µÇ¼ºó¸´ÖÆ
5.±àдÊÓͼÎļþ
ÊÓͼÎļþ£¨View£©ÊÇWebÓ¦ÓóÌÐòµÄÓû§½çÃ棬½ÓÄÉHTMLºÍCSSµÈÇ°¶ËÊÖÒÕ¡£ÒÔÏÂÊǶ©µ¥ÁбíÊÓͼÉè¼ÆµÄÊ÷Ä£´úÂ룺¡°
{extend name="layout"} {block name="content"} <h1>¶©µ¥Áбí</h1> <table> <thead> <tr> <th>¶©µ¥ºÅ</th> <th>Óû§</th> <th>ÎïÁ÷¹«Ë¾</th> <th>Ô˵¥ºÅ</th> <th>²Ù×÷</th> </tr> </thead> <tbody> {foreach $orderList as $order} <tr> <td>{$order.order_no}</td> <td>{$order.user.username}</td> <td>{$order.express.express_name}</td> <td>{$order.waybill_no}</td> <td> <a href="{:url(/help/'Order/getOrderDetail', ['orderId' => $order.order_id])}">ÏêÇé</a> </td> </tr> {/foreach} </tbody> </table> {/block}
µÇ¼ºó¸´ÖÆ
ÒÔÉÏÊÓͼÎļþÖÐÉæ¼°µ½µÄlayoutºÍurlº¯ÊýÐèÒªÊÂÏȾÙÐÐÉèÖã¬ÒÔ°ü¹ÜϵͳÕý³£ÔËÐС£
6.²âÊԺͰ²ÅÅ
±àд´úÂëºó£¬ÐèÒª¾ÙÐвâÊԺͰ²ÅÅ¡£¿ÉÒÔʹÓÃThinkPHP6ÌṩµÄÄÚÖÃWebЧÀÍÆ÷¾ÙÐвâÊÔ£¬Ê¹ÓÃÒÔÏÂÏÂÁîÆô¶¯WebЧÀÍÆ÷£º
php think run
µÇ¼ºó¸´ÖÆ
ÈôÊÇûÓÐÎÊÌ⣬¿É½«³ÌÐò°²Åŵ½Éú²úÇéÐÎÖС£
ËÄ¡¢×ܽá
±¾ÎÄÏÈÈÝÁËÔõÑùʹÓÃThinkPHP6¾ÙÐÐÎïÁ÷×·×Ù²Ù×÷¡£Í¨¹ý½¨ÉèÄ£×Ó¡¢¿ØÖÆÆ÷ºÍÊÓͼÎļþ£¬ÒÔ¼°¹ØÁªºÍÅÌÎʸ÷¸öÊý¾Ý±í£¬ÊµÏÖÁËÎïÁ÷×·×ÙϵͳµÄ»ù±¾¹¦Ð§¡£ËäÈ»£¬ÏÖʵµÄÎïÁ÷×·×ÙϵͳҪ±ÈÕâ¸öÖØ´óµÃ¶à£¬»¹ÐèÒªÉæ¼°¸ü¶àµÄÊÖÒÕºÍ֪ʶ¡£¿ÉÊDZ¾ÎÄÌṩµÄ˼Ð÷ºÍÒªÁì¿ÉÒÔΪʵÏÖ¸üÖØ´óµÄÎïÁ÷×·×ÙϵͳÌṩ²Î¿¼ºÍ½è¼ø¡£
ÒÔÉϾÍÊÇÔõÑùʹÓÃThinkPHP6¾ÙÐÐÎïÁ÷×·×Ù²Ù×÷£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡