ThinkPHP6ÈëÃŽ̳̣¬ÔõÑù¿ìËÙÉÏÊÖ£¿
Ëæ×Å»¥ÁªÍøµÄÒ»Ö±Éú³¤£¬Ô½À´Ô½¶àµÄÆóÒµ×îÏÈÒâʶµ½ÍøÕ¾¹ØÓÚÆóÒµµÄÖ÷ÒªÐÔ£¬ÔÚÕâÖÖÇéÐÎÏ£¬web¿ª·¢ÊÖÒÕÒ²»ñµÃÁ˼«´óµÄÉú³¤¡£¶ø¿ª·¢¹¤¾ß¾ÍÊÇÎÒÃÇÔÚweb¿ª·¢Àú³ÌÖбز»¿ÉÉÙµÄÒ»²¿·Ö¡£½ñÌìÎÒÃǾÍÀ´½²Ò»ÏÂÔõÑù¿ìËÙÉÏÊÖÒ»¸öphp¿ªÔ´¿ò¼Ü thinkphp6 µÄʹÓã¬×ÊÖú¸÷ÈËÔÚ¿ª·¢Àú³ÌÖÐÔ½·¢Ñ¸ËÙµÄÉÏÊÖ¡£
ÇéÐδ
ÔÚÎÒÃÇ×îÏÈѧϰ ThinkPHP6 µÄʹÓÃ֮ǰ£¬Ê×ÏÈÎÒÃÇÐèÒª´î½¨¿ª·¢ÇéÐΡ£ÎÒÃÇÐèÒªPHPÇéÐΣ¬¿ÉÒÔʹÓà XAMPP / WAMP ¾ÙÐÐ×°Öã¬Í¬Ê±»¹ÐèÒªÉèÖúà MySQL Êý¾Ý¿â¡£
ÏÂÔØ×°Öà ThinkPHP6
Íê³ÉÇéÐεĴ֮ºó£¬ÎÒÃǾͿÉÒÔÏÂÔØ×°Öà ThinkPHP6 ÁË¡£¿ÉÒÔÖ±½ÓÔÚ ThinkPHP ¹ÙÍøÏÂÔØ×°Öðü£¬Ò²¿ÉÒÔʹÓà Composer ¾ÙÐÐ×°Öá£ÏÂÃæÊÇʹÓà Composer ×°ÖõÄÒªÁ죺
composer create-project topthink/think tp6
µÇ¼ºó¸´ÖÆ
·ÓɺͿØÖÆÆ÷
ÔÚ ThinkPHP6 ÖУ¬Â·ÓɹØÓÚÏîÄ¿µÄ¿ª·¢ÊÇÖÁ¹ØÖ÷ÒªµÄ¡£ÎÒÃÇÐèÒªÉèÖú÷ÓÉÐÅÏ¢£¬²Å»ª¹»Èÿͻ§¶Ë»á¼ûµ½×¼È·µÄ¿ØÖÆÆ÷¼°Æä¶ÔÓ¦µÄÒªÁì¡£ÔÚ ThinkPHP6 ÖУ¬Â·ÓÉÉèÖÃÎļþΪ route/route.php¡£Ê¾Àý´úÂëÈçÏ£º
use thinkacadeRoute; Route::get('hello/:name', 'index/hello');
µÇ¼ºó¸´ÖÆ
ÉÏÃæµÄ´úÂëÌåÏÖ£¬ÎÒÃÇ¿ÉÒÔͨ¹ý http://localhost/hello/:name »á¼ûµ½ÃûΪ Index µÄ¿ØÖÆÆ÷ÖÐµÄ hello ÒªÁì¡£ÆäÖУ¬:name ÌåÏÖÎÒÃÇ¿ÉÒÔ´«ÈëÒ»¸ö²ÎÊý¡£
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
Ä£°åÒýÇæ
Ä£°åÒýÇæÊÇ web ¿ª·¢ÖкÜÊÇÖ÷ÒªµÄÒ»¸ö²¿·Ö£¬Ëü¿ÉÒÔ½«ÎÒÃǵÄÊý¾ÝÒÔ¸üºÃµÄ·½·¨·ºÆð¸øÓû§¡£ThinkPHP6 ÖÐĬÈÏʹÓõÄÄ£°åÒýÇæÊÇ Twig£¬ËüµÄʹÓúÜÊǼòÆÓ¡£ÔÚ¿ØÖÆÆ÷ÖÐʹÓà $this->assign() ÒªÁ콫Êý¾Ý´«ÈëÊÓͼÖм´¿É¡£Ê¾Àý´úÂëÈçÏ£º
public function index() { $this->assign('name', 'ThinkPHP'); return $this->fetch(); }
µÇ¼ºó¸´ÖÆ
ÔÚÉÏÃæµÄ´úÂëÖУ¬ÎÒÃÇÏòÊÓͼ´«ÈëÁËÒ»¸ö±äÁ¿ $name£¬È»ºóÔÚÊÓͼÖÐʹÓà {{ $name }} ¼´¿ÉÊä³ö¸Ã±äÁ¿¡£
×ܵÄÀ´Ëµ£¬ThinkPHP6 ÊÇÒ»¸öºÜÊÇÇ¿Ê¢µÄ PHP ¿ªÔ´¿ò¼Ü£¬Ëü²»µ«¹¦Ð§Ç¿Ê¢£¬²¢ÇÒʹÓÃÆðÀ´ºÜÊǼòÆÓ¡£Í¨³£ÇéÐÎÏ£¬ÎÒÃÇÖ»ÐèҪѧϰÆä»ù±¾Óï·¨£¬¾ÍÄܹ»¿ìËÙÉÏÊÖ¡£Í¨¹ý±¾ÎÄËùÌṩµÄѧϰҪÁ죬ÎÒÃÇÐÅÍи÷ÈËÄܹ»Ô½·¢Ñ¸ËÙµØÕÆÎÕ ThinkPHP6 µÄʹÓü¼ÇÉ£¬µÖ´ï¸üºÃµÄ¿ª·¢Ð§¹û¡£
ÒÔÉϾÍÊÇThinkPHP6ÈëÃŽ̳̣¬ÔõÑù¿ìËÙÉÏÊÖ£¿µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡