laravel Æô¶¯Àú³ÌÊÇʲô
laravelÊÇÒ»¿îÊ¢ÐеÄphp¿ªÔ´¿ò¼Ü£¬ËüµÄÆô¶¯Àú³ÌÓëÆäËû¿ò¼ÜÀàËÆ£¬¶¼ÐèÒªÂÄÀúÒ»¶¨µÄ×¼±¸ÊÂÇé¡£±¾ÎĽ«Õë¶ÔlaravelµÄÆô¶¯Àú³Ì¾ÙÐÐÏêϸÏÈÈÝ¡£
Ò»¡¢Èë¿ÚÎļþindex.php
LaravelµÄÈë¿ÚÎļþÊÇindex.php£¬ËùÓÐÇëÇ󶼽«Í¨¹ýÕâ¸öÎļþ½øÈë¿ò¼Ü¡£ÔÚindex.phpÖУ¬ÎÒÃÇ¿ÉÒÔ¿´µ½ÒÔÏ´úÂë¶Î£º
/* |-------------------------------------------------------------------------- | Turn On The Lights |-------------------------------------------------------------------------- | | We need to illuminate PHP development, so let us turn on the lights. | This bootstraps the framework and gets it ready for use, then it | will load up this application so that we can run it and send | the responses back to the browser and delight our users. | */ $app = require_once __DIR__.'/../bootstrap/app.php';
µÇ¼ºó¸´ÖÆ
Õâ¶Î×¢ÊÍÚ¹ÊÍÁË´úÂëµÄ×÷Óã¬Ò²¿ÉÒÔ¿´µ½require_onceÒýÈëÁËbootstrap/app.phpÕâ¸öÎļþ£¬Ò²¾ÍÊÇLaravelµÄÆô¶¯Îļþ¡£
¶þ¡¢Æô¶¯Îļþbootstrap/app.php
ÔÚapp.phpÎļþÖУ¬ÎÒÃÇ¿ÉÒÔÖ÷Òª¿´µ½Èý¸öÒªº¦ÀàµÄʵÀý»¯£º$app¡¢$kernel¡¢$router¡£ÏÂÃæÎÒÃÇÀ´ÖðÒ»ÏÈÈÝ¡£
$app
$appÊÇIlluminate\Foundation\ApplicationÀàµÄʵÀý£¬ÊÇÕû¸ö¿ò¼ÜµÄ½¹µã£¬ËüÖÎÀíÁË Laravel Ó¦ÓóÌÐòµÄÈÝÆ÷²¢ÌṩÁËÐí¶àÇ¿ÓÐÁ¦µÄ¹¦Ð§£¬Èç·ÓÉ¡¢ÇëÇó´¦Àí¡¢ÊÂÎñ¡¢cookie¡¢session¡¢Òì³£´¦ÀíµÈµÈ¡£½ÓÏÂÀ´ÎÒÃÇÏÈ¿´Ò»ÏÂ$appÔõÑù³õʼ»¯¡£
ÔÚ$appµÄ½á¹¹º¯ÊýÖУ¬ËüÊ×ÏȼÌÐøÁËIlluminate\Container\ContainerÀ࣬ÌìÉúÁËÒ»¸öÈÝÆ÷ʵÀý¡£ÔÚÕâ¸öÈÝÆ÷ʵÀýÖÐÎÒÃÇ¿ÉÒ԰󶨺Í×¢ÈëÎÒÃÇÐèÒªµÄЧÀÍ¡£
½Ó×Å£¬Ëü»á×¢²áLaravelµÄËùÓн¹µãÈÝÆ÷ЧÀÍ£¬Èç·ÓÉ¡¢ÈÕÖ¾¡¢ÊÓͼµÈ¡£
×îºó£¬Ëü»á¼ÓÔØLaravelÉèÖÃÎļþ£¬ÕâЩÉèÖÃÎļþ´æ·ÅÔÚconfigĿ¼Ï£¬²¢½«Æä·ÅÈë$appʵÀýµÄÊôÐÔÖС£
$kernel
$kernelÊÇIlluminate\Contracts\Http\Kernel½Ó¿ÚµÄÒ»¸öʵÀý£¬ËüÊÇLaravelµÄHTTPÄںˣ¬ÈÏÕæ´¦ÀíËùÓеÄHTTPÇëÇó£¬ÊÇÅþÁ¬ÇëÇóºÍÏìÓ¦µÄÇÅÁº¡£$kernelµÄÖ÷Òª×÷ÓÃÊÇŲÓÃÇëÇóµÄÖÐÐļþ£¬²¢½«ÇëÇóת´ï¸ø·ÓÉÆ÷£¬×îºó½«ÏìӦת´ï¸ø¿Í»§¶Ë¡£
ÔÚ$appʵÀý»¯ºó£¬Ëü»áŲÓÃ$app->make()ÒªÁìÈ»ºóͨ¹ýÈÝÆ÷ÆÊÎö»ñÈ¡$kernelµÄʵÀý¡£ÔÚÕâ¸öÀú³ÌÖУ¬$appµÄÈÝÆ÷»áÆÊÎö$config[‘app’][‘middleware’]ÉèÖò¢×¢²áÖÐÐļþ£¬È»ºó½«ÖÐÐļþ´æ´¢µ½$kernelµÄʵÀýÖС£
$router
$routerÊÇIlluminate\Routing\RouterÀàµÄʵÀý£¬ËüÊÇLaravelµÄ·ÓÉÆ÷£¬´¦ÀíËùÓеÄ·ÓÉÆÊÎöºÍ·Ö·¢¡£$routerµÄÖ÷Òª×÷ÓÃÊǽ«ÇëÇóºÍÏìÓ¦µÄ²Ù×÷¾ÙÐÐÆ¥Å䣬ΪÇëÇ󽫱»´¦ÀíµÄ·ÓÉ´æ´¢ÔÚÇëÇóʵÀýµÄÊôÐÔÖС£
ÔÚ$appʵÀý»¯ºó£¬Ëü»áʹÓÃÏìÓ¦µÄÉèÖÃÌìÉú·ÓÉÆ÷ʵÀý£¬²¢Í¨¹ý$appʵÀýµÄinstanceÒªÁì×¢²áµ½LaravelµÄÈÝÆ÷ÖС£
±ðµÄ£¬»¹ÐèÒªÌáµ½µÄÊÇ£¬$app»á½«ÇëÇóʵÀý¼°ÆäËüÏà¹ØʵÀý°ó¶¨µ½ÈÝÆ÷ÖУ¬ÒÔ¹©ÖÐÐļþ¡¢Â·ÓɺͿØÖÆÆ÷ʹÓá£ÈÝÆ÷°ó¶¨Íê³Éºó£¬Laravel¾ÍÍê³ÉÁË×¼±¸ÊÂÇé¡£
Èý¡¢µ÷ÀíÇëÇó
ÔÚLaravelÖУ¬ÇëÇóµÄµ÷ÀíÁ÷³ÌÈçÏ£º
1.´Ó¿Í»§¶ËÌᳫHTTPÇëÇó¡£
2.ÇëÇóÊ×ÏȾÓÉLaravelµÄpublic/index.phpÎļþ£¬²¢±»×ª·¢µ½bootstrap/app.phpÎļþÖС£
3.ÔÚbootstrap/app.phpÎļþÖУ¬LaravelÌìÉú$app¡¢$kernelºÍ$routerµÄʵÀý£¬²¢½«ÇëÇóʵÀý°ó¶¨µ½ÈÝÆ÷ÖС£È»ºó$app»áŲÓÃ$kernelµÄhandleÒªÁì´¦ÀíÇëÇó¡£
4.ÔÚ$kernelµÄhandleÒªÁìÖУ¬Laravelͨ¹ýÈÝÆ÷ÆÊÎö²¢ÒÀ´ÎŲÓÃ×¢²áµÄÖÐÐļþ£¬È»ºó½«ÇëÇóת·¢¸ø·ÓÉÆ÷¡£
5.ÔÚ·ÓÉÆ÷ÖУ¬Laravel´ÓÇëÇóÖÐÌáÈ¡URI£¬È»ºó½«ÆäÓë·ÓÉÆ÷ʵÀýÖнç˵µÄËùÓзÓɾÙÐÐÆ¥Åä¡£ÈôÊÇÕÒµ½Æ¥ÅäµÄ·ÓÉ£¬Laravel¾Í½«¿ØÖÆȨת´ï¸øÏìÓ¦µÄ¿ØÖÆÆ÷¡£
6.¿ØÖÆÆ÷ÊÇÇëÇóµÄÖ÷Òª´¦Àí³ÌÐò£¬Ëü»áŲÓÃÓªÒµÂß¼´úÂë´¦ÀíÇëÇ󣬲¢×îÖÕ½«Ð§¹û×÷ΪÏìÓ¦·µ»Ø¸ø¿Í»§¶Ë¡£
7.ÈôÊÇ·ÓÉÆ÷ûÓÐÕÒµ½Æ¥ÅäµÄ·ÓÉ£¬Ëü»á½«ÇëÇóת´ï¸ø¹ýʧ´¦Àí³ÌÐò¡£
8.ÔÚ¹ýʧ´¦Àí³ÌÐòÖУ¬Laravel»áƾ֤¹ýʧµÄÀàÐͺÍÉèÖã¬ÌìÉúÏìÓ¦µÄÏìÓ¦·µ»Ø¸ø¿Í»§¶Ë¡£
ÒÔÉϾÍÊÇÒ»¸öLaravelÇëÇóµÄÍêÕûÁ÷³Ì¡£Í¨¹ýÉîÈëÏàʶLaravelµÄÆô¶¯Àú³ÌºÍÇëÇóµ÷ÀíÁ÷³Ì£¬ÎÒÃÇ¿ÉÒÔ¸üºÃµÄÃ÷È·ËüµÄÄÚ²¿¼Ü¹¹ºÍÊÂÇéÔÀí£¬´Ó¶ø¸üºÃµØÔËÓÃËü´¦ÀíÎÒÃǵÄÓªÒµ¡£
ÒÔÉϾÍÊÇlaravel Æô¶¯Àú³ÌÊÇʲôµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡